Mac quick action - shrink images
Posted on February 8, 2022 (Last modified on July 11, 2024) • 1 min read • 157 wordsProblem: 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 …
quick action
Shell script action
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