Skip to content

Instantly share code, notes, and snippets.

@cuixin
Created January 4, 2019 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuixin/59a92f7cd16d6760496865cdfd38d02b to your computer and use it in GitHub Desktop.
Save cuixin/59a92f7cd16d6760496865cdfd38d02b to your computer and use it in GitHub Desktop.
tinpng bash example
#!/bin/bash
function tinypng() {
if [[ -z $APK_KEY ]]; then
echo "API_KEY not defined";
return 1;
fi
if [[ -z $1 ]]; then
echo "path is empty";
return 1;
fi
body=$(curl https://api.tinify.com/shrink \
--user api:$API_KEY \
--data-binary @$1)
echo $body
location=$(echo $body | jq '.output.url' | tr -d '"')
if [[ -z $location ]]; then
echo "download url is empty";
return 1;
fi
echo $location
curl $location \
--user api:$API_KEY \
--output $1
}
tinypng $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment