Last active
December 20, 2019 16:40
-
-
Save dawsbot/f8157cf47d5ffd7905e7130fb320d8ed to your computer and use it in GitHub Desktop.
Lossless image compression for all images in current directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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