Technical Marketing Guide

A travel guide for technical marketing – get inspired and start exploring yourself.

Quickly compress images with Automator (Mac)

Although data-plans are becoming bigger and bigger the size of a webpage still matters – according to many sources the page load time drastically affects all your important KPIs (most importantly your conversion rate).

One of the big reasons for larger websites are images. As our phones get better resolutions the images need to keep up and their size increases quite a bit.

But there is one really easy thing that you can do – and most people forget. You can compress images with minimal effects on the quality

There is a great service called TinyPNG that does exactly that: “PNG and JPEG compression with a perfect balance in quality and file size”

The technical marketers solution: Automate the process!

If you’re dealing with images on a regular bases you don’t want to have to open a web service every time you want to compress an image. How can this be done? I made a short video for you to follow along, the steps are explained below:

Instructions:

  • Fire up Automator (CMD + SPACE, “automator”, ENTER)
  • File > New, Select “Service”.
  • In the search field search for “run shell script”, drag the item to the right area.
  • Setup like this:
    • “Service receives selected” = “image files”
    • “in” = “finder”
    • “Shell” = “/bin/bash/”
    • “Pass input” = “as arguments”
  • Paste the following code into the text field below (delete the example code before)
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/Submarine.aiff
  • Request a API Key from TinyPNG
  • Click the Link in the Email TinyPNG sends you.
  • Copy the API Key and replace it in the code fragment where it states APIKEY.
  • File > Save!
  • Name the service how you want it to show up in the context menu. (Example: Compress Images).
  • Done! Right click on an image file in the finder an hit “Compress Images” to let the magic happen!

Disadvantage: You’re limited to 500 files per month, although I’ve found this to be quite a lot.

Next Post

Previous Post

Never miss another guide, sign up now

Cookie Settings

© 2023 Technical Marketing Guide | Imprint