Skip to content

Instantly share code, notes, and snippets.

@jinuljt
Created July 20, 2018 05:55
Show Gist options
  • Save jinuljt/5a8101032e3eac98281ac33bd58f69db to your computer and use it in GitHub Desktop.
Save jinuljt/5a8101032e3eac98281ac33bd58f69db to your computer and use it in GitHub Desktop.
#!/bin/bash
# require curl/wget/jq
TOKEN="<API key from https://tinypng.com/developers>"
if [ -z "$1" ]; then
echo "will create a shrink-<image_name> file"
echo ""
echo "usage:"
echo " tinypng <path/to/image.(png/jpg)>"
echo ""
echo "example:"
echo " tinypng ~/test.png"
exit 1
fi
DIR=`dirname "$1"`
OUTPUT=shrink-`basename "$1"`
echo "upload $1 to tinypng"
URL=`curl --user api:$TOKEN --data-binary @$1 https://api.tinify.com/shrink|jq -r ".output.url"`
echo "download shrinked image $URL"
wget $URL -O "$DIR/$OUTPUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment