How to rotate image using ImageMagick

Updated post here:

How to save image in different format

A common operation when working with images is to save them in a different format. Not surprisingly, ImageMagick has tools that make this very easy to perform at the shell.

The easiest way to save an image in a different format is to use convert:

$ convert foo.png bar.jpg

This saves an existing foo.png in PNG format to another file bar.jpg in the JPEG format.

Note that this command does not work if you want to convert a set of images. To do that, we use the mogrify command with its -format option.

To convert all PNG images in the current directory to JPEG format images keeping the same filename:

$ mogrify -format "jpg" *.png

Mogrify usually overwrites its source files. In this case however, the original PNG files are left untouched since the new files have a different file extension.

Tried with: ImageMagick 6.7.7 and Ubuntu 14.04

How to resize image using ImageMagick

ImageMagick provides convenient command-line tools for processing images. One common operation that I need is to resize or rescale images down to a certain height, width or percent.

To resize an image down to a width of 1024 pixels:

$ mogrify -geometry 1024x foo.jpg

To resize an image down to a height of 800 pixels:

$ mogrify -geometry x800 foo.jpg

To resize an image such that the longest side (either width or height) is 800 pixels:

$ mogrify -geometry 800x800 foo.jpg

To resize an image down by half:

$ mogrify -resize 50% foo.jpg

Tried with: ImageMagick 6.7.7-10 and Ubuntu 14.04