Skip to content

Instantly share code, notes, and snippets.

@jlopezcur
Last active April 1, 2019 23:31
Show Gist options
  • Save jlopezcur/7c76677aac6b6d660f99987129c9d317 to your computer and use it in GitHub Desktop.
Save jlopezcur/7c76677aac6b6d660f99987129c9d317 to your computer and use it in GitHub Desktop.
Optimize images
# The tools
sudo apt install libjpeg-progs optipng
# Compress jpg
jpegtran -copy none -optimize -perfect -outfile output.jpg input.jpg
# Compress png
optipng -o7 *.png
#!/bin/sh
# Copied from https://gist.github.com/iimos/7424025
# Usage 1:
# optimize-images.sh /images/dir
#
# Usage 2:
# cd /images/dir
# optimize-images.sh
EXTENSIONS="jpe?g"
if [ -z "$1" ]; then
DIR="`pwd`"
else
DIR="$1"
fi
# Optimize JPEG images
find "$DIR" -regextype posix-egrep -regex ".*\.($EXTENSIONS)\$" -type f | xargs -I{} jpegtran -optimize -progressive -outfile "{}" "{}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment