Created
January 4, 2019 09:55
-
-
Save cuixin/59a92f7cd16d6760496865cdfd38d02b to your computer and use it in GitHub Desktop.
tinpng bash example
This file contains 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 characters
#!/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