Created
December 22, 2014 23:30
Revisions
-
johnboxall renamed this gist
Dec 22, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
johnboxall created this gist
Dec 22, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ # Usage: # ./tinypng.sh <filename> <filename> <filename> # # Upload the files to shrink and then save them locally under the same name. # Only works with JPEG and PNG. # # Uses the TinyPNG API: https://tinypng.com/developers/reference # Inspired by this Gist: https://gist.github.com/s4l1h/553d00b71d4ab14c17d9 # # TODO: # * Only allow PNG and JPEG # * Confirm the images you want to resize. # * Test that images always get smaller. # * Don't fail anywhere. # * Add to githooks to automatically crush new files. # # set -x set -e set -o pipefail KEY=$TINYPNG_API_KEY if [ -z $TINYPNG_API_KEY ] ; then echo "Must set \$TINYPNG_API_KEY." exit 1 fi # -s = silent, no progress meter. # -i = include HTTP headers in the response, useful to grab the Location! # -f = fail, return non-zero if the command fails. # -o = output file # --data-binary = read from file for f in $@ ; do url=$(curl -sif --user "api:$KEY" --data-binary @$f https://api.tinypng.com/shrink | grep "Location:" | awk -F ' ' '{print $2}') curl -sf -o "$f" "$url" echo "Wrote $f" done