Skip to content

Instantly share code, notes, and snippets.

@iccir
Created May 4, 2017 01:13
Show Gist options
  • Save iccir/c0cbff2861d5353b1cef31be85dc8468 to your computer and use it in GitHub Desktop.
Save iccir/c0cbff2861d5353b1cef31be85dc8468 to your computer and use it in GitHub Desktop.
cpng
#!/bin/sh
IFS=$'\n'
FORCE=0
compress_png () {
more_args=""
if [[ $1 = og_* ]]; then
more_args="-c 0"
elif [[ $1 = g_* ]]; then
more_args="-c 4"
elif [[ $1 = o_* ]]; then
more_args="-c 2"
fi
pngcrush $more_args -rem alla -text b "[[cpng]]" "[[cpng]]" -e ".png_tmp" "$1"
optipng -o7 "$f"_tmp
mv "$f"_tmp "$f"
}
for f in $*
do
if [ "$f" == "-f" ]; then
FORCE=1
continue
fi
pngcheck -q -t "$f" | grep -q "[[cpng]]"
if [ $? -ne 0 ] || [ $FORCE -eq 1 ]; then
compress_png "$f"
else
echo "$f" "already compressed"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment