Last active
October 23, 2023 22:56
-
-
Save Git-I985/6a0ae20ae2c808ef25aa930810cbef56 to your computer and use it in GitHub Desktop.
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 | |
if [[ -z $TNF_API_KEY ]] | |
then | |
echo 'Error: TNF_API_KEY variable not found, please get api key from https://tinypng.com/developers and paste it in your ~/.zshrc or ~/.bashrc' | |
exit 1 | |
fi | |
for file in $(git status -s | grep -E '^[^D]{2}' | cut -c4- | grep -E "(.png|.jpg|.webp|.jpeg)") | |
do | |
response=$(curl -sS https://api.tinify.com/shrink \ | |
--user api:$TNF_API_KEY \ | |
--data-binary @$file) | |
output_url=$(echo $response | grep -oE "http[^\"]+") | |
if [[ -z $output_url ]] | |
then | |
echo "Cant find output url for $file"; | |
echo $response; | |
exit 1 | |
fi | |
echo $file $output_url; | |
curl -sS $output_url \ | |
--user api:$TNF_API_KEY \ | |
--output $file; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment