ImageMagick is a set of command-line utilities for modifying images. ImageMagick can perform modifications of an image from a terminal, perform batch processing of multiple images, or be used in a bash script.

Converting Between Formats

The following command takes a PNG file in the current directory and creates a JPEG file from it:

convert sample.png sample.jpg

Resizing Images

The following command tells ImageMagick to resize an image to 200 pixels in width and 100 pixels in height and overwrite the original file:

convert example.png -resize 200x100 example.png

ImageMagick will try to preserve the aspect ratio if you use this command. If you want to force the image to become a specific size – even if it changes the aspect ratio – add an exclamation point to the dimensions:

convert example.png -resize 200x100! example.png

You can also specify only a specific width or height and ImageMagick will resize the image while preserving the aspect ratio. The following command will resize an image to a width of 200:

convert example.png -resize 200 example.png

The following command will resize an image to a height of 100:

convert example.png -resize x100 example.png

Batch Processing

The following command would take all PNG files in the current directory, rotate them, and save a new copy of each with “rotated-” added to the beginning of each file name.

for file in *.png; do convert $file -rotate 90 rotated-$file; done

This is only a minor example of what ImageMagick can do. for more information, follow this link.

Leave a Reply

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