Skip to content

Instantly share code, notes, and snippets.

@dawsbot
Last active December 20, 2019 16:40
Show Gist options
  • Save dawsbot/f8157cf47d5ffd7905e7130fb320d8ed to your computer and use it in GitHub Desktop.
Save dawsbot/f8157cf47d5ffd7905e7130fb320d8ed to your computer and use it in GitHub Desktop.
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