The WebP format is a modern image format that provides superior lossless and lossy compression for images on the web. Developed by Google, WebP images are specifically designed for a faster web. And now that compatibility is very widespread, I find myself using them often on my websites.
While many image editing applications now support WebP, you might find yourself in a situation where you need to convert images to WebP in bulk or apply specific compression settings, and that’s where ImageMagick comes in handy.
Table of Contents
Why Use ImageMagick?
There are, of course, many image editing apps that work really well on Mac. So why would you want to start using a stripped-down command-line toolkit instead of the latest whiz-bang photo editing apps?
The answer lies in playing to strengths. There are some things that those apps are superb at. There are other things that ImageMagick really excels at.
ImageMagick is a really useful toolkit for image manipulation from the command line. It’s versatile, cross-platform, and free to use.
Despite lacking a graphical user interface, ImageMagick excels in batch processing and allows for intricate control over image conversion settings, making it a powerful tool for developers and photographers alike.
It fits in my photography workflow in two ways.
- It’s especially good at working with large numbers of images. Some GUI apps tend to choke if you feed them many thousands of images at once.
- It can be combined with Mac Automator Folder Actions to create watched folders for automatic conversions.
Checking WebP Support in ImageMagick
Before you start converting images to WebP, you’ll need to have ImageMagick with WebP support installed on your Mac. It’s not something that comes pre-installed on Mac. And while it’s not quite as simple as just copying something to your Applications folder, it’s still pretty straightforward. If you’ve followed my step-by-step guide for installing Homebrew and ImageMagick on Mac, you should be good to go.
How to Check for WebP Support
Even if you’ve installed ImageMagick at some point in the past, it still possible it might not have WebP support. To check, run this command in Terminal:
magick identify -list format | grep WebP
You should see WebP
listed among the supported formats, like this:

How to Update ImageMagick
If your ImageMagick installation doesn’t support WebP, you can update it quickly and easily.
First, make sure that Homebrew is the latest version with this:
brew update
Followed by this:
brew upgrade imagemagick
Then re-check the WebP support.
Converting Images to WebP with ImageMagick
WebP is especially suited for web use; that’s what it’s designed for. And it has developed wide compatibility with modern browsers.
In general, the files are considerably smaller than JPG versions, while they still retain good image quality. WebP is also especially good as a replacement for PNG and GIF files.
Here’s how to convert images to WebP, starting with a single file and moving to batch processing.
Simple Conversion of a Single File
To convert a single image to WebP:
magick input.png output.webp
Replace input.png
with your file’s name and output.webp
with the desired new file name. You don’t have to tell it explicitly to convert from one format to another; it’s inferring that from the file extensions.
Basic Batch Conversion
To convert multiple images in a folder to WebP:
for file in *.{jpg,png,gif}; do magick "$file" "${file%.*}.webp"; done
This will save the output WebP versions alongside the input JPG versions.
Specifying an Output Directory
To place the WebP files in a separate directory:
mkdir -p WebP
for file in *.{jpg,png,gif}; do magick "$file" "WebP/${file%.*}.webp"; done
Adjusting Compression
ImageMagick uses default settings for compression, but you can change this with the -quality
option:
magick input.png -quality 80 output.webp
A quality setting of 80 is often a good balance for WebP photos, but you can be much more aggressive as well, which will result in smaller file sizes. I often use around 60 or 65 for graphics files.
Additional Encoding Options
There are a number of other options you can use when using ImageMagick to encode WebP images.
- Lossless Compression: Add
-define webp:lossless=true
for lossless compression. - Encoding Speed: Use
-define webp:method=6
for slower encoding with better compression. - Alpha Channel Quality: Set alpha quality with
-define webp:alpha-quality=100
. - Near-Lossless Compression: Use
-define webp:near-lossless=50
for nearly lossless compression.
Here’s an example with these settings:
magick input.png -quality 80 -define webp:lossless=false -define webp:method=6 -define webp:alpha-quality=100 -define webp:near-lossless=50 output.webp
Automating WebP Conversion with macOS Folder Actions
Using macOS’s Folder Actions with Automator, you can set up a watched folder to auto-convert images to WebP. This is where things really start to take off from a workflow efficiency standpoint.
- Create a Folder Action in Automator.
- Use “Run Shell Script” with
Pass input
asas arguments
. - Set the Shell to
/bin/zsh
. - Insert the script to convert the file formats you’re targeting.
For example, this is what I used for my WebP watched folder. Yes, it’s more complicated than the most basic version could be. But it also does a few other things in addition to simple conversion. It automatically converts any images dropped or copied into the folder to WebP at a quality setting of 70 and then moves the input files to Trash (where you can recover them if need be). And it looks for specific image file types, which isn’t technically necessary to specify, but I find useful.

There’s a bunch of ways you can modify and customize this. You could have it recursively process folders or do other tasks at the same time, like add a watermark or border. But if you’d like to use it as a starting point, here’s a version you can copy and paste.
for f in "$@"
do
# Extract the file extension and base name
ext="${f##*.}"
filename="${f%.*}"
# Define the output file path with the .webp extension
outfile="${filename}.webp"
# Check for specific image file extensions
if [[ "$ext" == "jpg" || "$ext" == "jpeg" || "$ext" == "bmp" || "$ext" == "gif" || "$ext" == "avif" || "$ext" == "png" || "$ext" == "heif" || "$ext" == "heic" ]]; then
# Convert the image file to WebP using ImageMagick with specified settings
/usr/local/bin/magick "$f" -quality 70 -strip "${f%.*}.webp"
# Move the original image file to the trash using AppleScript
osascript -e 'tell application "Finder" to delete POSIX file "'"$f"'"'
fi
done
It’s well worth running some tests to check that it’s performing as expected for your needs. And you can, of course, modify the quality setting to your preferences. I find something around 60-70 good for general graphics use, but it’s often too low for photos, where detail suffers. So, for photos, I’ll usually use something like 80 or 85.
An example of where I’m often using WebP for the master version is with graphics files I’ve created in Canva. For still images, Canva gives you the choice of downloading PNG or JPG. But both options tend to result in filesizes far larger than they should be. So I’ll often crunch them down to WebP before uploading them to my site.
More Things You Can Do with ImageMagick
There’s a lot you can do with ImageMagick. I’m in the process of putting together some guides for tasks that are especially relevant to photography workflows.
For example:
- How to Convert to AVIF with ImageMagick
- How to Strip all Metadata from Images using ImageMagick
- How to Add a Plain Border to Images using ImageMagick
Stay tuned: I’ll add them here as I create new ones.