• Bubble
  • Bubble
  • Line
Batch Image Modification and resizing in the command line with GraphicsMagick
Andrei Clinciu Article AUthor
Andrei Clinciu
  • 2016-11-26T16:34:00Z
  • 1 min to read

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

 

Ideas and comments

Andrei Clinciu
Andrei Clinciu

I'm a Full Stack Software Developer specializing in creating websites and applications which aid businesses to automate. Software which can help you simplify your life. Let's work together!

Building Great Software
The digital Revolution begins when you learn to automate with personalized software.

Find me on social media