Skip to content

Instantly share code, notes, and snippets.

@bashcoder
Forked from dgageot/pre-commit
Created February 17, 2013 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bashcoder/4970312 to your computer and use it in GitHub Desktop.
Save bashcoder/4970312 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