Skip to content

Instantly share code, notes, and snippets.

@hoyangtsai
Created July 14, 2016 08:01
Show Gist options
  • Save hoyangtsai/750bc407aca3449356d690fbde8de77a to your computer and use it in GitHub Desktop.
Save hoyangtsai/750bc407aca3449356d690fbde8de77a to your computer and use it in GitHub Desktop.
Automator Compress Images Right-click Service
for f in "$@"
do
echo $f | while IFS= read file
do
filename=$(basename $file)
ext=$(echo ${filename##*.} | tr "[:upper:]" "[:lower:]")
if [ -f $file ]
then
if ( [ $ext == "png" ] || [ $ext == "jpg" ] || [ $ext == "jpeg" ] )
then
JSON=`curl -i --user api:APIKEY --data-binary @$file https://api.tinypng.com/shrink 2>/dev/null `
URL=${JSON/*url\":\"/}
URL=${URL/\"*/}
curl $URL>${file} 2>/dev/null
fi
fi
done
done
afplay /System/Library/Sounds/Glass.aiff
@hoyangtsai
Copy link
Author

hoyangtsai commented Aug 10, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment