Image Manipulation Using ImageMagick Command-Line Tools

Image Manipulation Using ImageMagick Command-Line Tools

Postby yiboj » Mon Oct 03, 2016 8:46 pm

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

test_in.png
Before
test_in.png (25.04 KiB) Viewed 3984 times
test_out.png
After 45 degree Rotation
test_out.png (86.92 KiB) Viewed 3984 times


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

test_in.png
Before
test_in.png (25.04 KiB) Viewed 3984 times
test_out.png
Implode Effect
test_out.png (65.15 KiB) Viewed 3983 times


The following command applies the “negate” effect:

convert test_in.png -negate test_out.png

test_in.png
Before
test_in.png (25.04 KiB) Viewed 3984 times
test_out.png
Negate Effect
test_out.png (25.38 KiB) Viewed 3983 times


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/
yiboj
 
Posts: 130
Joined: Mon Mar 30, 2015 11:22 am

Return to Visualization

cron