Skip to content

Instantly share code, notes, and snippets.

@web2ls
Created September 2, 2018 20:25
Show Gist options
  • Select an option

  • Save web2ls/f1a4c28c003f27e9830fed5cb7fc05e1 to your computer and use it in GitHub Desktop.

Select an option

Save web2ls/f1a4c28c003f27e9830fed5cb7fc05e1 to your computer and use it in GitHub Desktop.
ImageMagick compress images
// For .png format
// common
convert INPUT.gif_or_png -strip [-resize WxH] [-alpha Remove] OUTPUT.png
// example
convert cuppa.png -strip cuppa_converted.png
//For .jpg format
//common
convert INPUT.jpg -sampling-factor 4:2:0 -strip [-resize WxH] [-quality N] [-interlace JPEG] [-colorspace Gray/sRGB] OUTPUT.jpg
// example
convert puzzle.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace sRGB puzzle_converted.jpg
// short description
Reduce quality to 85 if it was higher. With quality larger than 85, the image becomes larger quickly, while the visual improvement is little.
Reduce Chroma sampling to 4:2:0, because human visual system is less sensitive to colors as compared to luminance.
Use progressive format for images over 10k bytes. Progressive JPEG usually has higher compression ratio than baseline JPEG for large image, and has the benefits of progressively rendering.
Use grayscale color space if the image is black and white.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment