Skip to content

Instantly share code, notes, and snippets.

@davebeach
Last active October 31, 2016 05:06
Show Gist options
  • Save davebeach/2c6b672e5e34056f414088f81104bfa7 to your computer and use it in GitHub Desktop.
Save davebeach/2c6b672e5e34056f414088f81104bfa7 to your computer and use it in GitHub Desktop.

ImageMagick Workflow via Command Line

Install - Global

Mac OS X

brew install imagemagick

For LiNUX Cloud Server Command Line

apt-get install imagemagick

Important Background

  • You need to escape where necessary. IE if you have a command convert max-width.jpg -resize 200\> max-width-resized.jpg You need to escape the > character.

Key Commands

Identify Command

The advantage of identify, is that you can also feed it without extensions. This function will allow you to quickly determine the image type, dimensions and how color is managed.

identify file

To customize the output use -print

identify -format "Name: %f Type: %P Dimensions: %m" filename

Resize Image

convert puppy.jpg -resize 80% resized.puppy.jpg

Batch Resize

Create batch folder - mkdir ./resize/batch

convert *.jpg -resize 80% -set filename:f '%t@2x' '%[filename:f].jpg'

Add set for filename by adding :f at the end filename:f Add %t followed by @2x to represent a retina image.

Strip Meta Data

Meta data takes up image file size space, it should be removed.

Retina to Non-Retina Image Workflow

  1. Make sure to have extra copies of original image.
  2. Start with retina image and optimize it and append @2x.
  3. Use mogrify to reduce file size for non-retina. Example mogrify !(*@2x).jpg -resize 40%

Basic Workflow to Reduce Image File Size

  1. Quality reduction
  2. Progressive (comprobed compression)
  3. Possible need for small blur if required.
  4. Strip meta data.
convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85% source.jpg result.jpg

Reference

Good blog on ImageMagick by Nick Tomlin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment