Skip to content

Instantly share code, notes, and snippets.

@dgageot
Created March 28, 2010 01:43
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dgageot/346489 to your computer and use it in GitHub Desktop.
Save dgageot/346489 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Pre-commit hook that crushes PNG files in order to reduce their size.
if ! which -s pngcrush
then
echo "Please install pngcrush to reduce png images size before commit"
exit 1;
fi
for file in `git diff --cached --name-only | grep ".png\$"`
do
echo "Crushing $file"
pngcrush -rem allb -brute -reduce $file ${file%.png}.new | grep "filesize"
mv -f ${file%.png}.new $file
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment