-
-
Save jemekite/d115c0f5b79574058a25 to your computer and use it in GitHub Desktop.
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 | |
# | |
# Home-rolled Smush.it, by Alex Dunae (http://dialect.ca). Modified by Abidkecil | |
# | |
# N.B. This script works for me; it may not work for you. | |
# Since it overwrites your images with the optimized version, you should | |
# backup your files before running this script and do a trial run before | |
# getting too excited. This is your disclaimer. | |
# | |
# Uses jpegtran (http://jpegclub.org/jpegtran/), part of libjpeg, | |
# and zopflipng (https://github.com/google/zopfli). | |
# Ubuntu install: sudo apt install libjpeg-turbo-progs zopfli -y | |
# Set to WordPress upload directory or any folder with images. | |
base_path=~/Downloads/images/ | |
# Find files with a JPG extension recursively and process with jpegtran by | |
# - stripping comments | |
# - optimize image table | |
# - making the JPEG progressive | |
if type -P jpegtran &>/dev/null; then | |
echo 'Running jpegtran'; | |
find $base_path -iname "*.jpg" -type f -exec jpegtran -outfile '{}' -copy none -optimize -progressive '{}' \; | |
else | |
echo 'jpegtran not found'; | |
fi | |
# Find files with a PNG extension recursively and process with ZopfliPNG | |
if type -P zopflipng &>/dev/null; then | |
echo 'Running ZopfliPNG'; | |
find $base_path -iname "*.png" -type f -exec zopflipng -y --lossy_transparent '{}' '{}' \; | |
else | |
echo 'zopflipng not found'; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment