Resize your images using imagemagick

Imagemagick is a wonderful image manipulation tool.
it is a Free and Open Source Software.

It is a CLI  (Command Line Interface) tool. not a GUI one like GIMP,
Photoshop, Inkscape etc..

So what a CLI tool can do on images?
Do you wonder?

The imagemagick can do mostly all the things we do with GIMP.

Add border, colorize, comment, contrast, crop, dispose, dither, emboss,enhance, extract, fill, filter, flip, flop, format, frame, gamma, geometry,mask, monochrome, negate, noise, normalise, blur, resample, resize,  rotate,scale, sepia, shade, shadow, sharpen, stretch, strip, thumbnail, tile,transparent, trim, unsharp and more.

well. but why a CLI tool for image manipulation?

CLI always rocks on Bulk Operations.
                                

To convert a colour photo into black and white, we can use GIMP and apply a
filter and do that job.

But, if you want to do the same for 1000 photos?
what you will do?

You will get frustrated if you do it manually.
won’t you?

Let us take a real problem.

Nowadays, we have a lot of Digital Photos from our digital cameras, mobile
phones etc.

Most people have very high resolution cameras like 7 to 10 Megapixel cameras.
The images are high in density and quality.
They are upto 3-5 MB in size each.
the resolution is
This high quality is good for printing.

But, we normally, we don’t print them all.
we just view them, send via email, upload to picasaweb or flickr.

For viewing in the monitor, 800×600 resolution is enough.
If  we reduced the resolution, the file size will be automatically reduced.

the size of a 640×480 image is 57K only.
we can reduce the file size from 5MB to 57K by reducing resolution.

How to reduce the resolution of all the images we have?
going manually is hectic job.

Here the CLI tool rocks.

Imagemagick is software which contains a collection of small tools like
convert, mogrify and more.

To install imagemagick in ubuntu and debian linux,
run
           

    sudo apt-get install imagemagick

for windows, download from
http://www.imagemagick.org/script/binary-releases.php

Let us use mogrify.

                mogrify -resize 640×480  -verbose *.jpg

this command will resize all the jpg images in the current folder to 640×480
resolution.

Now, the file size will be reduced to around 50K.
now you can send mail or upload.

Note:
All the original images are affected.
and there is no “Undo”.
so, make sure that a backup is always there.

To know more what imagemagick can do on images,
come here.
http://www.imagemagick.org/Usage/

Powered by ScribeFire.

5 thoughts on “Resize your images using imagemagick

  1. It’s very unfortunate that you use the term “resolution” incorrectly.

    What you’re talking about is image size, which is called “geometry” in ImageMagick.

    Using identify (identify -verbose example_image.jpg ) we can see two very different pieces of information:

    Geometry: 160×200 — which is the size of the image, width by height, and

    Resolution: 360×360
    Units: PixelsPerInch — which is the resolution.

    Resolution is set by the -density command line option:

    –density width
    –density widthxheight

    horizontal and vertical resolution in pixels of the image.

    What resolution you use for an image is dependent on what you’re going to do with it: whether it’s for the web, for newspaper print production, or for high-end full color magazine or book print production.

  2. ‘Mogrify’ now takes a ‘path’ argument, so that if you create a subdirectory named ‘whatever’ you can use this command and leave the originals untouched:

    mogrify -path whatever -resize 800×600 *.jpg

    The resized images are left in the ‘whatever’ directory.

    Be sure to use the (.jpg, .tiff, etc) file extension, as otherwise Imagemagick gets confused looking for the file named ‘whatever.’

  3. You could also do it in a for loop from bash like this, and use convert so that you don’t touch the original file…

    for f in *.jpg ; do
    ff=`echo $f|sed ‘s/\.[^.]*$//’`
    echo “processing $ff”
    convert -resize 640×480 $f ${ff}-NEW.jpg
    done

    that is the fun way!

    Eric

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s