How to Use ImageMagick to Convert Images to WebP on Mac

If you have to convert a bunch of images to WebP or set up automatic conversion on your Mac, ImageMagick is a great option. Here’s how to set it up for batch conversion to WebP or watched folders for automatic converting.

Screenshot of Automator Folder Action on Mac for a watched folder for automatically converting images to WebP
Text & Photos By David Coleman

I MAY get commissions for purchases made through links in this post.

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.

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.

  1. 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.
  2. 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:

Screenshot of Mac Terminal window showing WebP compatibility with ImageMagick

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.

  1. Create a Folder Action in Automator.
  2. Use “Run Shell Script” with Pass input as as arguments.
  3. Set the Shell to /bin/zsh.
  4. 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.

Screenshot of Automator Folder Action on Mac for a watched folder for automatically converting images to WebP

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 "$@"
    # Extract the file extension and base name

    # Define the output file path with the .webp extension

    # 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"'"'

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:

Stay tuned: I’ll add them here as I create new ones.

Profile photo of David Coleman | Have Camera Will Travel | Washington DC-based Professional Photographer

Text & Photos by David Coleman

I'm a professional photographer based in Washington DC. Seven continents, up mountains, underwater, and a bunch of places in between. I've been shooting for 30+ years, and my my photos and time-lapse videos have appeared in a bunch of different publications from major newspapers to magazines and books, billboards, TV shows, professional sports stadiums, museums, and even massive architectural scrims covering world-famous buildings while they're being renovated. You can see some of my travel photography here and here.

Leave a Comment