Batch Image Modification and resizing in the command line with GraphicsMagick

/images/blog/cc/abstract_creativity_wallpaper_hd_colorss_by_ovii_graphics.jpeg
abstract creativity wallpaper hd colorss by ovii graphics

GraphicsMagick is an enhanced version of ImageMagick which is a Image library used by many applications and websites to edit images.

The main strength of GraphicsMagick is the power it can harness on multicore devices via OpenMP.

You can download binaries and the source code from http://www.graphicsmagick.org/

On Linux you can install it by either running one of the following commands depending on the flavour, Redhat vs Debian.

dnf install graphicsmagickapt-get install graphicsmagick

Note that in recent versions of CentOS or Fedora yum has been replaced by dnf

You can run all imagemagick commands into graphicsmagick format by just typing gm

The following command was issued on a directory containing aproximately 1200 JPG images that where over 20 MB each to resize them. The output was around 800kb to 1 mb per image on a 2000 px height to a standard calculated width per image. In other words by using 2000x or x2000 graphicsmagick automatically calculates the width/height and sets the correct resolution.

gm mogrify -create-directories -output-directory "/home/path/to/pictures" -verbose -quality 85 -resize 2000x modification/*.JPG

Building a tile based image from multiple images

gm montage '*png' -tile 4 -background none -mode concatenate bird_yellow.png

Multiple actions on an image

Let’s say we have a big list of images and want to resize them, convert them to .jpg, and add a copyright logo image, plus create a thumbnail/.

cd /your/images/locationoutputlocation="/home/lostone/images/output/"logo="/home/lostone/images/logo.png"for file in *.pngdooutfile=img-`basename $file .png`.jpggm convert -verbose "$file" -resize x1000 -strip -quality 85 "$location/$outfile"gm composite -gravity SouthEast $logo $outfile $outfilegm convert -verbose "$outfile" -resize x500 -strip -quality 85 "$location/thumbnails/$outfile"done

 

Subscribe to my Newsletter

Receive emails about Linux, Programming, Automation, Life tips & Tricks and information about projects I'm working on