Created
July 14, 2016 08:01
-
-
Save hoyangtsai/750bc407aca3449356d690fbde8de77a to your computer and use it in GitHub Desktop.
Automator Compress Images Right-click Service
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: http://danielsetzermann.com/howto/how-to-compress-png-files/