Instantly share code, notes, and snippets.

Embed
What would you like to do?
image optimization script (pngcrush & jpegtran)
#!/bin/sh
# script for optimizing images in a directory (recursive)
# pngcrush & jpegtran settings from:
# http://developer.yahoo.com/performance/rules.html#opt_images
# pngcrush
for png in `find $1 -iname "*.png"`; do
echo "crushing $png ..."
pngcrush -rem alla -reduce -brute "$png" temp.png
# preserve original on error
if [ $? = 0 ]; then
mv -f temp.png $png
else
rm temp.png
fi
done
# jpegtran
for jpg in `find $1 -iname "*.jpg"`; do
echo "crushing $jpg ..."
jpegtran -copy none -optimize -perfect "$jpg" > temp.jpg
# preserve original on error
if [ $? = 0 ]; then
mv -f temp.jpg $jpg
else
rm temp.jpg
fi
done
@rauldelperal

This comment has been minimized.

Copy link

rauldelperal commented Aug 1, 2013

Muchas gracias! Vamos a probar!!

@petrabarus

This comment has been minimized.

Copy link

petrabarus commented Sep 17, 2013

nice one! thanks!

@shiroi2003

This comment has been minimized.

Copy link

shiroi2003 commented Mar 12, 2014

Excellent. thank you!

@vikaslaxmi

This comment has been minimized.

Copy link

vikaslaxmi commented Mar 16, 2015

How can we use these functions for our website, that is hosted on Linux with PHP coding using my Sql.

@tedivm

This comment has been minimized.

Copy link

tedivm commented Jun 9, 2017

Add this to the top to make it work with files that have spaces in them.

IFS=$'\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment