Created
July 2, 2013 02:30
-
-
Save AndrewRayCode/5906379 to your computer and use it in GitHub Desktop.
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 | |
compression=80 | |
hasExif=`which exiftool` | |
pngs=`git status -s | grep .png | awk '{print $2}'` | |
arr=($pngs) | |
if [ -n "$arr" ]; then | |
echo "Compressing png images by $compression%..." | |
for png in "${arr[@]}" | |
do | |
oldSize=`exiftool -FileSize $png | awk '{print $4$5}'` | |
pngquant --quality=80 --ext=.png --force $png | |
newSize=`exiftool -FileSize $png | awk '{print $4$5}'` | |
git add $png | |
echo " Compressed $png from $oldSize to $newSize" | |
done | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Git pre commit hook to compress (modified) png files, and automatically add them to the commit. This assumes you are exporting the data from a PSD / image editing program every time you make a change, so you will not re-compress a compressed image.
put the gist in
.git/hooks/pre-commit
Remember, you cannot commit git hooks, so you must add this to any machine you wish to have it on (yes, git is dumb)