Skip to content

Instantly share code, notes, and snippets.

@sinabio
Forked from rkbhochalya/optimize-images.sh
Created June 8, 2022 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinabio/b4406d212a5acba3550ac0ad3b404504 to your computer and use it in GitHub Desktop.
Save sinabio/b4406d212a5acba3550ac0ad3b404504 to your computer and use it in GitHub Desktop.
Recursively optimize PNG and JPEG images using convert command
# Recursively optimize PNG and JPEG images using convert command
#
# `convert` is part of ImageMagick (http://www.imagemagick.org/). You will need to install it first.
#
# Author: Rajendra Kumar Bhochalya (http://rkb.io)
#
# @see https://developers.google.com/speed/docs/insights/OptimizeImages
# Optimize all JPEG images in current directory and subdirectories
find . -name "*.jpg" -exec convert "{}" -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace RGB "{}" \; -exec echo "{}" \;
# Optimize all PNG images in current directory and subdirectories
find . -name "*.png" -exec convert "{}" -strip "{}" \; -exec echo "{}" \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment