Skip to content

Instantly share code, notes, and snippets.

@nanmu42
Created August 5, 2019 03:48
Show Gist options
  • Save nanmu42/10f87271a0b057ff62879d68de5a2ea2 to your computer and use it in GitHub Desktop.
Save nanmu42/10f87271a0b057ff62879d68de5a2ea2 to your computer and use it in GitHub Desktop.
Opitimize JPEG and PNG to a both smaller file size and resolution
#!/usr/bin/env bash
FOLDER=$1
MAX_WIDTH=1400
MAX_HEIGHT=1000
# resize, strip metadata and save in a lower quality
# aspect ratio will be kept.
find ${FOLDER} \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' \) -exec convert \{} -verbose -strip -quality 75 -resize "${MAX_WIDTH}x${MAX_HEIGHT}>" \{} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment