Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lossless image compression for all images in current directory
#!/bin/bash
# Minify all jpg and png images in current directory recursively
command_exists () {
type "$1" &> /dev/null ;
}
# Learn more about optipng at http://sweetme.at/2013/09/11/how-to-maximize-png-image-compression-with-optipng/
if command_exists optipng ; then
optipng -o2 -strip all **/*.png
else
echo 'Error: optipng is not installed. If you are on a Mac, we recommend googling "homebrew Mac" and installing via brew' >&2
exit 1
fi
# Learn more about jpegoptim at https://guides.wp-bullet.com/batch-compress-jpeg-images-lossless-linux-command-line/
if command_exists jpegoptim ; then
jpegoptim --strip-all **/*.{jpg,jpeg}
else
echo 'Error: jpegoptim is not installed. If you are on a Mac, we recommend googling "homebrew Mac" and installing via brew' >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.