ItecSoftware Logo

ImageMagick from command line

Written by Peter Gilg on - like this:
imagemagick from commandline

ImageMagick is such a cool and powerful tool to manipulate images, it’s a real shame if you don’t make use of it during your web design or photo album creation. You can resize, compose and convert all types of image files, it’s list of usability cases is endless. And best of all it’s free and available for almost every operating system.

If you don’t have it on your system yet, here is the imagemagick download location. You might also have it in your repository, check your package manager (Synaptic on Ubuntu or Yum on CentOS) as it might be as simple as calling “sudo apt-get install imagemagick” (on Ubuntu) or “sudo yum install imagemagick” (on Red Hat/CentOs).

Here is a small compilation of command-line tools (by no means a complete list). The list of available commands is actually sheer endless, you’ll be amazed by how powerful this application is.

Imagemagick from command line

imagemagick resize

convert image.gif -resize 128×128 resized_image.gif

imagemagick crop

convert  image.gif  -crop 240×360  cropped-image.gif      (add’l params for crop location: 240×360+10+10)

imagemagick rotate

convert image.gif -rotate 90 rotated-image.gif

imagemagick mirror

convert image.gif  -flop mirrored-image.gif

Example of ImageMagick from command line

There are many more, actually way too many to list them all here. Have a look at the official ImageMagick usage page for a complete list of image manipulation actions. It amazes me every time how easy it is to crop and resize thousand of images with one single command with ImageMagick.

For example, this command will create thumbnails for all jpg files in the current directory, to fit into 200 pixel wide and high, depending on the format. For example, if your image is in landscape layout, it’ll be 200 pixel wide, in portrait format it’ll be 200 pixel high.

for file in *.jpg ; do convert -resize 200 "$file" t"$file"; done

We just created thumbnails 200 pixels in size of all the images in a given directory. You can simply exchange 200 with the size you require, or change the extension if your images are in gif, png or any other image format.


Listed in Linux, Useful Stuff, Web Development

Tags: command line, crop, image, imagemagick, resize, rotate

Leave a Reply

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