ImageMagick WebP: Convert, Resize, and Encode Images

Use ImageMagick’s convert and magick commands to encode images to WebP format with quality settings, resize options, and WebP-specific defines.

ImageMagick supports WebP through its bundled libwebp delegate, making it easy to convert images to WebP using the same convert (v6) or magick (v7) commands you already use in your workflow. Because WebP encoding is integrated into ImageMagick’s processing pipeline, you can combine colour correction, resizing, cropping, and format conversion into a single command.

Prerequisites #

Before converting images to WebP, verify that your ImageMagick installation was compiled with WebP delegate support.

# Check if WebP delegate is available
convert -list format | grep -i webp
# Should show: WEBP* rw- WebP Image Format

If the command returns no output, your ImageMagick build lacks WebP support. Reinstall ImageMagick from your package manager — most modern distributions ship a version compiled with libwebp included.

Basic Conversion #

Pass a source image and a .webp output filename. ImageMagick infers the target format from the file extension automatically.

# ImageMagick 7
magick input.jpg -quality 80 output.webp

# ImageMagick 6
convert input.jpg -quality 80 output.webp

The Quality Parameter #

ImageMagick maps the -quality value (0–100) directly to cwebp’s internal quality parameter when encoding WebP output. Higher values preserve more detail at the cost of larger file sizes.

Low Quality (50–65) #

Smallest files. Acceptable for thumbnails or previews where pixel-perfect accuracy is not required.

Best balance of file size and visual quality for photographic content. Use this range for production images.

High Quality (90–100) #

Near-original quality. Suitable for archival or post-processing workflows where the WebP will be edited further.

Lossless Mode #

Enable lossless encoding with the webp:lossless define. This is the preferred method for logos, icons, and images where every pixel must match the source exactly.

magick input.png -define webp:lossless=true output.webp

WebP-Specific Defines #

ImageMagick exposes the full set of cwebp encoding options through the -define webp:* mechanism. Combine multiple defines in a single command to fine-tune the output.

# Lossless encoding
magick input.png -define webp:lossless=true output.webp

# Set encoding method (0-6); higher values = smaller files, slower encoding
magick input.jpg -quality 80 -define webp:method=6 output.webp

# Set alpha channel quality for transparent images
magick input.png -quality 80 -define webp:alpha-quality=100 output.webp

# Enable near-lossless pre-processing (0 = maximum, 100 = off)
magick input.png -define webp:near-lossless=50 output.webp

The full list of supported -define webp:* keys mirrors the flags exposed by the cwebp binary. Refer to the ImageMagick WebP delegate documentation for the complete reference.

Resizing and Converting in One Step #

Combine -resize with the WebP output format to produce scaled images without intermediate files. This is one of ImageMagick’s key advantages over invoking cwebp directly.

# Resize to 800px wide, maintain aspect ratio, convert to WebP
magick input.jpg -resize 800x -quality 80 output.webp

# Generate a square 200x200 thumbnail centred on the subject
magick input.jpg -resize 200x200^ -gravity center -extent 200x200 -quality 75 thumb.webp
  1. Choose your source file — Provide a JPEG, PNG, TIFF, or any other format that ImageMagick can decode. The delegate handles the rest.
  2. Add processing operations — Chain resize, crop, colour profile, or any other ImageMagick operation before the output argument.
  3. Set a .webp output filename — ImageMagick detects the target format from the .webp extension and routes encoding through the libwebp delegate automatically.

ImageMagick’s WebP delegate requires libwebp ≥ 0.3.0. Most modern Linux distributions, macOS Homebrew builds, and the official Windows installers ship with a compatible version. If you encounter encoding errors, run magick -version and check that webp appears in the delegate list.

Use cwebp directly when you need maximum control over encoding parameters such as per-segment quality, hint modes, or spatial noise shaping. ImageMagick is the better choice when WebP conversion is one step inside a larger image processing pipeline — for example, when you also need to strip colour profiles, watermark images, or apply filters in the same operation.

If you just need to convert a few images quickly and don’t have ImageMagick installed, our free WebP converter in your browser does the job entirely client-side.

Was this page helpful?