Dieser Artikel ist derzeit nur auf Englisch verfügbar.

CLIApr 5, 20268 min read

Best CLI Tools to Batch Convert Images to WebP in 2026

Jack avatar
JackAuthor

Best CLI Tools to Batch Convert Images to WebP in 2026

You have a folder full of images. Maybe it is 50 product photos, maybe it is 500 screenshots from a documentation site. You need them all converted to WebP. You want a CLI tool that handles it in one command.

But which one should you reach for?

There are four serious options in 2026. Each has real strengths and real weaknesses. This article puts them side by side with actual benchmarks, actual install commands, and actual batch conversion syntax so you can pick the right one for your workflow.

The Contenders#

cwebp (Google's Reference Encoder)#

Google built the WebP format, and cwebp is their official command-line encoder. It ships as part of the libwebp package and has been around since 2010. It does one thing: convert a single image to WebP. No batch mode, no recursive directory scanning, no built-in quality presets beyond the basics. If you want to convert a folder, you are writing shell scripts.

ImageMagick#

The Swiss army knife of image processing. ImageMagick can read and write over 200 image formats, apply hundreds of transformations, and has been a staple of server-side image pipelines for decades. It is powerful — but that power comes at a cost. The install is heavy (roughly 200MB with dependencies), and the infamous policy.xml security configuration has caused countless headaches in Docker and CI environments.

Sharp (Node.js)#

Sharp wraps the native libvips library in a clean Node.js API. It is fast — often the fastest option in benchmarks — because it delegates the heavy lifting to compiled C code. The catch is that "compiled C code" part. Sharp relies on pre-built native binaries, and when those binaries do not match your platform, Node version, or container base image, you get cryptic node-gyp errors. If you have ever spent an hour debugging Sharp in an Alpine Docker container, you know the pain.

GetWebP#

GetWebP takes a different approach entirely. It compiles the WebP encoder to WebAssembly and bundles it as a single npm package with zero native dependencies. No node-gyp, no libvips, no platform-specific binaries. It runs wherever Node.js runs. The trade-off is speed — WASM is slower than native code. But the install story is npx getwebp . and you are done.

Installation Comparison#

This is where the tools start to diverge in a meaningful way.

cwebp:

# macOS
brew install webp

# Ubuntu/Debian
apt install webp

# Windows
# Download precompiled binaries from Google, add to PATH manually

Platform-specific. Different commands on every OS. Windows requires manual binary management.

ImageMagick:

# macOS
brew install imagemagick

# Ubuntu/Debian
apt install imagemagick

# Installs ~200MB of dependencies

Heavy install. Works everywhere, but the policy.xml file often blocks PDF and SVG processing by default for security reasons. Debugging this in CI is a recurring time sink.

Sharp:

npm install sharp

Looks simple. Works great — until it does not. Sharp downloads pre-built native binaries for your specific OS, architecture, and Node version. If there is no match, it falls back to building from source with node-gyp, which requires Python and a C++ compiler. In Docker, this means your node:alpine image needs extra build dependencies, and your build time doubles.

GetWebP:

npx getwebp .

Nothing to install. The npx command downloads and runs GetWebP in one step. No native dependencies, no build step, no platform-specific binaries. Works on macOS, Linux, Windows, Docker, CI — anywhere Node.js 18+ is available.

Batch Conversion Syntax#

The real test: "convert every image in this folder to WebP." Here is how each tool handles it.

cwebp:

for f in *.jpg; do
  cwebp "$f" -o "${f%.jpg}.webp"
done

You need a separate loop for each file extension. Want to handle PNG too? Add another loop. Want recursive directory scanning? Wrap it in find. Want progress output? Add echo statements. You are basically writing a bash script every time.

ImageMagick:

magick mogrify -format webp *.jpg

Cleaner, but limited. This converts files in the current directory only — no recursion. All output goes to the same directory. If you want to customize quality per format or handle mixed input types, you are back to scripting.

Sharp:

// convert.js
const sharp = require('sharp');
const fs = require('fs');
const path = require('path');

const dir = './images';
const files = fs.readdirSync(dir).filter(f => /\.(jpg|png)$/i.test(f));

(async () => {
  for (const file of files) {
    const input = path.join(dir, file);
    const output = path.join(dir, file.replace(/\.(jpg|png)$/i, '.webp'));
    await sharp(input).webp({ quality: 80 }).toFile(output);
  }
})();

At minimum, you are writing 10+ lines of JavaScript. Want recursion? Add a directory walker. Want progress bars? Add a dependency. Want error handling? More code. Sharp is a library, not a tool — the ergonomics are up to you.

GetWebP:

# Convert all images in a directory (recursive)
npx getwebp ./images --quality 80 -r

One command. Pass -r for recursive directory traversal. Auto-detects JPEG, PNG, and other supported formats. Outputs WebP files alongside the originals. Progress output built in.

Benchmark: Real Numbers on Real Images#

We ran each tool against the same set of images on the same machine to get an honest comparison. Here are the results.

ImageInput SizeGetWebPSharpImageMagick
320x240 JPEG40 KB206ms / 11 KB89ms / 11 KB33ms / 11 KB
640x480 JPEG138 KB252ms / 34 KB114ms / 34 KB60ms / 34 KB
800x600 PNG2.4 MB324ms / 45 KB150ms / 45 KB92ms / 45 KB
1024x768 PNG3.9 MB390ms / 64 KB192ms / 64 KB132ms / 64 KB
1024x768 JPEG302 KB360ms / 70 KB161ms / 70 KB110ms / 70 KB
1920x1080 JPEG768 KB643ms / 163 KB331ms / 163 KB276ms / 163 KB
2048x1536 PNG15.6 MB975ms / 201 KB495ms / 201 KB419ms / 196 KB
4096x3072 JPEG3.8 MB2736ms / 730 KB1196ms / 730 KB1250ms / 730 KB

Time = wall-clock conversion time. Output size = resulting WebP file size.

The pattern is clear: Sharp and ImageMagick are faster. They run native compiled code, and it shows. GetWebP is roughly 2x slower across the board because WASM, while fast, cannot match native C performance.

But look at the output sizes. They are virtually identical. GetWebP uses the same WebP encoding algorithm (it is literally the same libwebp compiled to WASM), so the output quality and compression ratio are the same. You are not sacrificing image quality for portability.

For a typical batch of 100 images, the difference might be 2 minutes vs. 4 minutes. In a CI pipeline that runs nightly, that is irrelevant. In a developer workflow where you run the conversion once and move on, it barely registers.

The Real Trade-off#

Let's be honest about what you are choosing between.

If raw speed is everything and you control the environment, Sharp wins. You know your target OS. You know your Node version. You can ensure libvips installs cleanly. In that scenario, Sharp is fast, produces great output, and has a solid API.

If you need it to work everywhere without thinking about it, GetWebP wins. CI runners with unpredictable base images. Docker containers you did not build. A teammate's Windows laptop. A GitHub Action that should just work. In these scenarios, the zero-dependency approach eliminates an entire class of problems.

If you are on a server you fully control and want maximum flexibility, ImageMagick is hard to beat. It handles formats no other tool supports, and once it is installed and configured, it is rock solid.

If you just need to convert one file, cwebp is fine. It is small, focused, and does exactly what it says.

The hidden cost that benchmarks do not capture is the install tax. That is the 45 minutes you spend debugging why Sharp cannot find libvips in your Alpine container. Or the hour you lose because ImageMagick's policy.xml blocks WebP encoding in your CI environment. Or the frustration of writing platform-specific install scripts for cwebp across macOS, Ubuntu, and Windows runners.

GetWebP's value proposition is not speed. It is the guarantee that npx getwebp . works on the first try, every time, on every platform.

Verdict and Quick Start#

For most developers who need to batch convert images to WebP from the command line, GetWebP offers the best balance of simplicity and reliability. It is slower than native tools, and this article has shown you exactly how much slower. But it eliminates the setup friction that makes those native tools painful in modern, multi-platform development workflows.

Here is how to get started:

# Convert all images in current directory to WebP
npx getwebp .

# Specify a directory and quality level
npx getwebp ./images --quality 80

The free tier converts up to 20 images per invocation with a short pause between files — enough for most personal projects and testing. The Pro tier removes both the per-run cap and the inter-file delay for teams and production pipelines.

If speed is your only concern and you are willing to manage native dependencies, Sharp or ImageMagick will serve you well. But if you want a tool that works the first time you run it, with no install step and no platform surprises, give GetWebP a try. The command is one line, and the results speak for themselves.

Jack avatar

Jack

Author