Skip to content

Instantly share code, notes, and snippets.

@victoriadrake
Created May 22, 2018 14:11
Show Gist options
  • Save victoriadrake/c54993193f5462f5af1cb17e22fd2233 to your computer and use it in GitHub Desktop.
Save victoriadrake/c54993193f5462f5af1cb17e22fd2233 to your computer and use it in GitHub Desktop.
A pre-commit hook that optimizes images in-place in the current directory.
#!/bin/sh
# in git repo: cp pre-commit-imgopt .git/hooks
# add execute permissions: chmod +x .git/hooks/pre-commit-imgopt
find . -name '*.png' -print0 | xargs -0 -P8 -n2 optipng -o5
find . -name '*.jpg' -print0 | xargs -0 -P8 -n2 jpegoptim --strip-all -m30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment