Batch convert images using ImageMagick

ImageMagick provides one of the best command line image processing tools for Linux. With a support for almost a hundred different formats, ImageMagick can be used to compose, edit, process images in batch and also add text, draw various objects, superimpose them – there’s no end to the capabilities of ImageMagick. We will be going through a series of tutorials with ImageMagick. Today’s tutorial will focus on basics of using ImageMagick and later on resizing images.

ImageMagick Basic Commands:

As already mentioned, ImageMagick comes with a set of tools which allow operating on images from the command line, saving a lot of time.

Convert: This is the basic command in ImageMagick. It can be used to convert one form of image into another.

$aditya@archie:/>convert image.jpg image.png

This is the most basic form of image conversion. It changes format of the image. You can also add a bunch of parameters, like

$aditya@archie:/>convert image.jpg -resize 75% image.png

to convert the image while reducing it’s size.

Mogrify: This tool is used for doing batch processing on images. This is similar to convert, except that when used without proper understanding, mogrify can destroy original image. Similar to convert, mogrify can be used to convert format of images. To convert all jpg images in a directory to png, issue following command in that directory.
$aditya@archie:/>mogrify -format png *.jpg
This command will create a png version of all the images in a directory. However, it will overwrite all png files with same name in that directory without any warning. This tool can be dangerous, so think before you use it. You can create thumbnails of all images using something like this,

$aditya@archie:/> mogrify -path thumb -thumbnail 100x100 *

This will create a 100px X 100px thumbnail of all images in current directory and place them in (already created) thumb subdirectory. You can resize all images using

$aditya@archie:/> mogrify -resize 800x600 *

This will keep proportions. To change the aspect ratio and resize image given size, add an exclamation mark (!) after the image size. Like, 800×600\!.  Happy conversion!

3 thoughts on “Batch convert images using ImageMagick

  1. DOES NOT WORK ON WINDOWS COMPUTER FOR BATCH CONVERSIONS (even though I have the windows version of IM)! I have a whole folder full of SVG files and tried substituting in SVG to get them into PNG, like this

    mogrify -format png *.svg

    but it doesn’t work! Give me a WORKING COMMAND LINE FOR THIS!!!!!

  2. THIS is the error it gives me.

    C:\Users\Ben hutchinson\Desktop\ImageMagick-6.7.2-8>mogrify -format png *.svg
    mogrify: Unescaped ‘<' not allowed in attributes values
    `No such file or directory` @ error/svg.c/SVGError/2624.
    mogrify: attributes construct error
    `No such file or directory` @ error/svg.c/SVGError/2624.
    mogrify: error parsing attribute name
    `No such file or directory` @ error/svg.c/SVGError/2624.
    mogrify: attributes construct error
    `No such file or directory` @ error/svg.c/SVGError/2624.
    mogrify: xmlParseStartTag: problem parsing attributes
    `No such file or directory` @ error/svg.c/SVGError/2624.
    mogrify: Couldn't find end of Start Tag g
    `No such file or directory` @ error/svg.c/SVGError/2624.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>