Skip to content

Instantly share code, notes, and snippets.

@cuixin
Created Jan 4, 2019
Embed
What would you like to do?
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