Image Manipulation Using ImageMagick Command-Line Tools

ImageMagick is not a GUI image editor like Photoshop etc., it is designed for batch processing of images, and a suite of command-line utilities for modifying and working with images. ImageMagick can perform a wide variety of operations. This guide will introduce you to ImageMagick’s syntax and basic operations and show you how to combine operations and perform batch processing of many images.
Converting Between Formats
ImageMagick can convert any image format into another as shown in the following command to convert png file into jpg file:
convert test_in.png test_out.jpg
Image Rotation
ImageMagick can quickly rotate an image. The following command takes an image named test_in.jpg, rotates it by 90 degrees and saves the rotated image as test_out.jpg:
convert test_in.png -rotate 45 test_out.png
Resizing Images
The convert command can also quickly resize an image. The following command asks ImageMagick to resize an image to 200 pixels in width and 100 pixels in height:
convert test_in.png -resize 200×100 test_out.png
More Image Operators
There are lots more image operators include:
‑annotate • ‑black‑threshold • ‑blur • ‑border • ‑charcoal • ‑chop • ‑clip • ‑clip‑path • ‑clip‑mask • ‑colors • ‑colorize • ‑colorspace • ‑compose • ‑contrast • ‑convolve • ‑crop • ‑cycle • ‑despeckle • ‑draw • ‑edge • ‑emboss • ‑enhance • ‑equalize • ‑evaluate • ‑extent • ‑flip • ‑flop • ‑floodfill • ‑frame • ‑gamma • ‑gaussian‑blur • ‑grayscale • ‑implode • ‑lat • ‑level • ‑map • ‑median • ‑modulate • ‑monochrome • ‑negate • ‑noise • ‑normalize • ‑opaque • ‑ordered‑dither • ‑paint • ‑posterize • ‑raise • ‑profile • ‑radial‑blur • ‑raise • ‑random‑threshold • ‑resample • ‑resize • ‑roll • ‑rotate • ‑sample • ‑scale • ‑sepia‑tone • ‑segment • ‑shade • ‑shadow • ‑sharpen • ‑shave • ‑shear • ‑sigmoidal‑contrast • ‑solarize • ‑splice • ‑spread • ‑strip • ‑swirl • ‑threshold • ‑transparent • ‑thumbnail • ‑tint • ‑transform • ‑trim • ‑unsharp • ‑version • ‑wave • ‑white‑point • ‑white‑threshold
The following command applies the “Implode” effect with a strength of 1:
convert test_in.png -implode 1 test_out.png
The following command applies the “negate” effect:
convert test_in.png -negate test_out.png
Create Animation
ImageMagick can animate various image formats, the following command will just animate the various frames:
animate test*.gif
Using the following command to create animated gif file from a serious image frames:
convert -delay 20 -loop 0 test*.gif animate.gif
Batch Processing
You can take advantage of Bash to quickly do batch processing of many images. For example, 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
For more information, please refer to the following references:
1. http://www.imagemagick.org/
2. http://www.howtogeek.com/109369/how-to- ... -terminal/
Converting Between Formats
ImageMagick can convert any image format into another as shown in the following command to convert png file into jpg file:
convert test_in.png test_out.jpg
Image Rotation
ImageMagick can quickly rotate an image. The following command takes an image named test_in.jpg, rotates it by 90 degrees and saves the rotated image as test_out.jpg:
convert test_in.png -rotate 45 test_out.png
Resizing Images
The convert command can also quickly resize an image. The following command asks ImageMagick to resize an image to 200 pixels in width and 100 pixels in height:
convert test_in.png -resize 200×100 test_out.png
More Image Operators
There are lots more image operators include:
‑annotate • ‑black‑threshold • ‑blur • ‑border • ‑charcoal • ‑chop • ‑clip • ‑clip‑path • ‑clip‑mask • ‑colors • ‑colorize • ‑colorspace • ‑compose • ‑contrast • ‑convolve • ‑crop • ‑cycle • ‑despeckle • ‑draw • ‑edge • ‑emboss • ‑enhance • ‑equalize • ‑evaluate • ‑extent • ‑flip • ‑flop • ‑floodfill • ‑frame • ‑gamma • ‑gaussian‑blur • ‑grayscale • ‑implode • ‑lat • ‑level • ‑map • ‑median • ‑modulate • ‑monochrome • ‑negate • ‑noise • ‑normalize • ‑opaque • ‑ordered‑dither • ‑paint • ‑posterize • ‑raise • ‑profile • ‑radial‑blur • ‑raise • ‑random‑threshold • ‑resample • ‑resize • ‑roll • ‑rotate • ‑sample • ‑scale • ‑sepia‑tone • ‑segment • ‑shade • ‑shadow • ‑sharpen • ‑shave • ‑shear • ‑sigmoidal‑contrast • ‑solarize • ‑splice • ‑spread • ‑strip • ‑swirl • ‑threshold • ‑transparent • ‑thumbnail • ‑tint • ‑transform • ‑trim • ‑unsharp • ‑version • ‑wave • ‑white‑point • ‑white‑threshold
The following command applies the “Implode” effect with a strength of 1:
convert test_in.png -implode 1 test_out.png
The following command applies the “negate” effect:
convert test_in.png -negate test_out.png
Create Animation
ImageMagick can animate various image formats, the following command will just animate the various frames:
animate test*.gif
Using the following command to create animated gif file from a serious image frames:
convert -delay 20 -loop 0 test*.gif animate.gif
Batch Processing
You can take advantage of Bash to quickly do batch processing of many images. For example, 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
For more information, please refer to the following references:
1. http://www.imagemagick.org/
2. http://www.howtogeek.com/109369/how-to- ... -terminal/