A great deal of my time working as a web/UI designer is spent exporting and/or converting images for software products and websites. Although a lot of modern applications can render image conversions at build time, a custom conversion is sometimes requested for an image to be set as webp
.
You could download one of the many native apps from the Mac App Store to do this for you - but why not create your own script and run it with a simple right-click directly inside Finder? Let’s do just that!
Important!: As of this time of writing, the official libwebp
package release is libwebp-1.2.1-mac-10.15. If this has been updated since then, change the command below to match that of the proper release version.
libwebp
package to your Downloads folder: libwebp package
cwebp
folder to our /usr/local/bin
directory:
sudo cp /Downloads/libwebp-1.2.1-mac-10.15/bin/cwebp /usr/local/bin
/usr/local/bin
directory doesn’t exist, simply create it by running: sudo cd /usr/local && mkdir bin
Open the macOS Automator from the Applications folder
Select Quick Option
from the first prompt
Set “Workflow receives current” to image files
Set the label “in” to Finder
From the left pane, select “Library > Utilities”
From the presented choices in the next pane, drag and drop Run Shell Script
into the far right pane
Set the area “Pass input” to as arguments
Enter the following code below as your script and type ⌘-S
to save (name it something like “Convert to webp”)
for f in "$@"
do
/usr/local/bin/cwebp -q 85 "$f" -o "${f%.*}.webp"
done
For visual reference, it should look something like this:
And when right-clicking an image file in the Finder window, it should now give you the option to convert:
If you ever have the need to edit this script (for example, changing the default 85
quality parameter), you will need to navigate to your ~/Library/Services
folder and open your custom webp Quick Action in the Automator application.
Simple as that!
I was contacted by the very helpful Kev Quirk about a minor problem he encountered while following this tutorial. When trying to run cwebp
he received the following error message:
cwebp cannot be opened because it's from an unverified developer
Doing the next steps seemed to have fixed this issue for him:
cwebp
utility to open in TerminalAfter following these steps, the issue should be resolved.
I'm extremely grateful for the support from the "Hall of Fame" supporters:
adast.dk
alessandrocuzzocrea.com
alexeystar.com
arc-x.org
artemislena.eu
b0ba.dev
cleberg.net
danielsada.tech
dieses-veganismus.de
gtrr.artemislena.eu
iosis-labs.com
jakobmagnusson.se
jamieonkeys.dev
kristianscott.co.uk
lukealexdavis.co.uk
miniskirt.me
nicksherman.com
simone.org
t0.vc
tedmagaoay.com
willem.com
wonger.dev
xslendi.xyz
zoraster.org
If you too would like to support this project and help fund more articles like this one:
Become a supporter today →