Automate Everything




I’m preparing a set of images for upload for a future blog post and started to make the edits in Photoshop but quickly became frustrated with the work required.  For each image I had to:

  1. Shrink the image from 4000×5000 down to 480×600
  2. Increase the canvas to 640×520
  3. Place a 20 pixel border on the image
  4. Change the font smoothing to smooth for each text region
  5. Pray everything lines up or fix it manually

The problem was not everything was clean when I expanded the images in step 2 so getting a smooth edge was proving to be a challenge.  I remembered that  ImageMagick had some nifty commands to do the same thing in seconds.  Allow me to explain.

ImageMagick processes commands from left to right.

mogrify -resize 600x600 -bordercolor black -border 20 -format png *.jpg

Mogrify is the command in ImageMagick to run a batch set of commands.  In this case on all jpg files.  This command does the following order of operations:

  1. Sets the size of the image to no wider than 600 pixels. This handles landscape and portrait images.  600×600 is the bounding box.
  2. Sets the border color to black
  3. Adds a 20 pixel border on all sides of the image
  4. Exports the image in the PNG file format.

Sure, I could have done everything with Photoshop no problem.  What having a “build script” does it it prepares your assets in a reproducible way.  It’s easy then to change the border color, make the border bigger, or resize the image.  I just re-run the script with the new values.  One point of note, the output to PNG is specific.  Had I done JPG, the converter would overwrite my originals.

For more examples on ImageMagick


Related Posts

Subscribe to the Dashed Yellow Line!


Leave a Reply