Skip to content

Instantly share code, notes, and snippets.

@pavgup
Last active August 29, 2015 14:20
Show Gist options
  • Save pavgup/49009ebb3f083a4c44f7 to your computer and use it in GitHub Desktop.
Save pavgup/49009ebb3f083a4c44f7 to your computer and use it in GitHub Desktop.
This is a wee bit dangerous when used in isolation. It will search for all files that *nix believes is an image and will then use imagemin (npm install -g imagemin if you need it) to begin optimizing assuming the defaults are worth trusting. This is not lossless. It does make a backup of each file inside the current working directory inside, con…
#!/bin/sh
mkdir backup;
for file in $(
find . -exec \
file {} \; | \
awk -F':' '{ if ($2 ~/[Ii]mage|EPS/) print $1,"\n"}'| \
sed s/\.//);
do
cp -R -v .$file ./backup/;
imagemin .$file > .$file.tmp;
mv -f .$file.tmp .$file;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment