Created
April 18, 2012 11:16
-
-
Save ftf/2412955 to your computer and use it in GitHub Desktop.
little script for optimizing images
This file contains hidden or 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 | |
# tools needed: optipng, libjpeg for libtrans and gifsicle | |
MEDIAFOLDER=~/Development/octopress/source/media | |
MEMORYFILE=$MEDIAFOLDER/.optimized | |
for img in $MEDIAFOLDER/*.{png,jpg,jpeg,gif}; do | |
if [ `grep $img $MEMORYFILE 2>/dev/null | wc -l` -eq 0 ]; then | |
if [[ $img =~ \.png$ ]]; then | |
/usr/local/bin/optipng -o7 $img | |
elif [[ $img =~ \.(jpg|jpeg)$ ]]; then | |
/usr/local/bin/jpegtran -optimize -outfile $img $img | |
elif [[ $img =~ \.gif$ ]]; then | |
/usr/local/bin/gifsicle --optimize=2 --no-warnings --batch $img | |
fi | |
echo $img >> $MEMORYFILE | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment