Fly, Penguin!

I blog so I don't forget.

Mac quick action - shrink images

1 minute read #automation #desktop #mac

Problem: A list of images, which are big. And one wants to make them smaller, maybe for the web.

Solution: A Mac Automator quick action.

Prerequisites: GNU parallel, ImageMagick (both via homebrew)

You …

  • open Automator
  • create a new quick action
  • add Shell script action
  • paste in the script below
  • make sure arguments are passed via stdin

automator quick action for shrinking images

export PATH=$PATH:/usr/local/bin
export size=1280

# that SHOULD work, but DOES NOT (at least not on my machine)
#parallel -a - convert {1} -resize "${size}x${size}\>" -quality {2} {1.}.${size}px.{2}.{3} ::: 50 80 ::: webp jpg

# that works.
TMP=$(mktemp)
cat > "$TMP"
parallel -r convert {1} -geometry "${size}x${size}\>" -quality {2} {1.}.${size}px.q{2}.{3} :::: "$TMP" ::: 50 80 ::: webp jpg
rm "$TMP"

… or use the easier to understand, non-parallel version:

export PATH=$PATH:/usr/local/bin
export size=1280

while read f ; do
  for ext in webp jpg ; do
    for q in 50 80 ; do
      convert "$f" -resize ${size}x${size} -quality $q "${f%.*}.$size.q$q.$ext"
    done
  done
done