ImgParser

Convert a folder of PNGs to WebP with ImageMagick

Convert multiple images from Bash, keep the original PNGs and check the format, dimensions and size of each result.

1. Check ImageMagick and prepare your folders

Open your working directory in the terminal. If your usual shell is zsh, type bash to start a Bash session and paste the commands there. Type exit when you want to return to zsh.

magick -version should report ImageMagick 7, and the WEBP row in the format list should show rw or rw+. If you need to install it, see the official ImageMagick downloads.

magick -version
magick -list format | grep -E '^[[:space:]]+WEBP[[:space:]*]'
mkdir -p ./input ./output-webp

Copy your .png files into input. To try the commands with small files first, download the transparent logo and the screenshot with text.

2. Convert all PNGs in the folder

magick mogrify -path ./output-webp -format webp -strip -quality 85 ./input/*.png

-path writes the results to output-webp and -format webp changes the extension. The command keeps the source PNGs and preserves their dimensions. The -strip flag removes profiles and metadata from the output. Omit this flag and check the result if your workflow depends on those details.

The *.png pattern selects lowercase extensions in that folder. For .PNG files, run a separate batch with the matching pattern and a different output directory if names overlap. The command can overwrite existing WebP files with the same names. Use a fresh output directory to keep earlier results.

3. Verify the results

magick identify -format '%f %m %wx%h %b\n' ./output-webp/*.webp

The output shows the name, detected format, dimensions and size of each WebP. If the conversion command reports missing files, check that input contains .png files and that you are running the command from your working directory.

To keep every pixel in a logo or screenshot, create a separate lossless WebP batch. Separate output directories let you compare file sizes and appearance.

mkdir -p ./output-webp-lossless
magick mogrify -path ./output-webp-lossless -format webp \
  -strip -define webp:lossless=true -define webp:exact=true -quality 85 ./input/*.png

The PNG, JPEG and WebP comparison shows both WebP modes using a photo, a logo and a screenshot. For a single file, try the browser-based PNG to WebP converter.

See the official ImageMagick documentation. mogrify · WebP options