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!