Comparing index PNG to tinyPNG always results in smaller but better files coming out of tinyPNG. Something about their dithering perhaps?
For instance compare best quality 256 indexed png:
To drag into TinyPNG
TinyPNG is also about 200k smaller on this particular file.
So, I’m wondering if it can run the file through TinyPNG via AppleScript or Shell?
I’ve found the following for automator shell set to bin/bash as arguments. But I’m not sure how to implement it into Retrobatch? I don’t need it to ask my api each time. I’d rather just enter it into the script once and forget it.
CONFIG=~/Library/Caches/TinyPNG
if [ -f $CONFIG ]; then
APIKEY=$(<$CONFIG)
else
APIKEY="$(osascript -e ‘Tell application “System Events” to display dialog “Enter a TinyPNG api key:” default answer “”’ -e ‘text returned of result’ 2>/dev/null)"
if [ $? -ne 0 ]; then
# The user pressed Cancel
exit 1 # exit with an error status
elif [ -z “$APIKEY” ]; then
# The user left the project name blank
osascript -e ‘Tell application “System Events” to display alert “You must enter a TinyPNG api key; cancelling…” as warning’
exit 1 # exit with an error status
fi
echo “$APIKEY” > $CONFIG
fi
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
if [[ $JSON == error ]]
then
ERROR=${JSON/error":"/}
ERROR=${ERROR/","/}
osascript -e ‘Tell application “System Events” to display alert “The TinyPNG api key is wrong!; cancelling…” as warning’
exit 1
else
URL=${JSON/url":"/}
URL=${URL/"/}
curl $URL>"${file}" 2>/dev/null
fi
fi
fi
done
done
Any ideas? Thanks!