Last active
April 1, 2019 23:31
-
-
Save jlopezcur/7c76677aac6b6d660f99987129c9d317 to your computer and use it in GitHub Desktop.
Optimize images
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
# 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 |
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/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