ImageMagick basic

By xngo on February 21, 2019

Overview

ImageMagick is very powerful command line tool to manipulate images. It can "resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves".

Basic

# Resize image
    magick convert -verbose -resize 50% -quality 80   input.jpg output.jpg
    magick mogrify -verbose -resize 50% -quality 80%  *.jpg     # Will overwrite orignal files.
    magick mogrify -verbose -resize 800x600 -density 25x25 -path output_dir/  *input.files.png
 
    # Width=600px
    magick mogrify -verbose -resize x600 -density 25x25 -path output_dir/  *input.files.png
 
# Convert color to grayscale
    magick convert input.jpg -colorspace Gray output.jpg
    magick convert input.jpg -type Grayscale  output.jpg
 
# Get image resolution.
    magick identify -format "%wx%h" image.jpg
 
# Add border.
    magick convert input.png -bordercolor black -border 1%x1% output.png
 
# Add 2 images.
    # From top to bottom.
    magick convert -append top.png bottom.png output.png
 
    # From left to right.
    magick convert +append left.png right.png output.png
 
# Create favicon.ico
    magick convert -background none favicon.png -define icon:auto-resize=64,48,32,16 favicon.ico

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.