Skip to content

Instantly share code, notes, and snippets.

@aaronjolson
Created November 21, 2014 17:20
Show Gist options
  • Save aaronjolson/e4be58a656315064342b to your computer and use it in GitHub Desktop.
Save aaronjolson/e4be58a656315064342b to your computer and use it in GitHub Desktop.
A bash script to be pasted into bashrc. Use the crush command to compress multiple jpgs and pngs inside of a directory. Requires pngcrush and libjpeg-progs
### Crush multiple image files in a folder
crush() {
for f in *;
do
mv "$f" `echo $f | tr ' ' '_'`
done
for f in *.png
do
echo "$f"
pngcrush -brute "$f"{,.} && du -b "$f"{,.}
cp -f "$f." "$f"
rm -f "$f."
done
for f in *.jpg
do
echo "$f"
jpegtran "$f" > "$f." && du -b "$f"{,.}
cp -f "$f." "$f"
rm -f "$f."
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment