Convert PNG to WebP on Linux and Ubuntu — Terminal and Browser Methods
- cwebp (Google official): cwebp -q 80 input.png -o output.webp
- ImageMagick: magick convert input.png -quality 80 output.webp
- Browser tool: open in Firefox or Chrome — no install needed
- All methods support lossless conversion and preserve transparency
Table of Contents
Linux has the best WebP tooling of any platform. Google's official cwebp encoder is a one-line install, ImageMagick handles it natively, and a browser-based converter works without installing anything. All three preserve transparency and support both lossy and lossless modes.
Here is how to convert PNG to WebP on any Linux distro.
Method 1: cwebp — Google Official WebP Encoder
cwebp is the reference WebP encoder from Google. It gives you the most control over WebP-specific encoding options.
Install:
# Ubuntu/Debian sudo apt install webp # Fedora sudo dnf install libwebp-tools # Arch sudo pacman -S libwebp
Lossy conversion:
cwebp -q 80 input.png -o output.webp
Lossless conversion:
cwebp -lossless input.png -o output.webp
Batch convert all PNGs:
for f in *.png; do cwebp -q 80 "$f" -o "$(basename "$f" .png).webp"; done
Lossless batch:
for f in *.png; do cwebp -lossless "$f" -o "$(basename "$f" .png).webp"; done
cwebp also supports alpha channel quality control (-alpha_q), preprocessing filter strength (-f), and near-lossless mode (-near_lossless). For most conversions, -q 80 or -lossless covers everything you need.
Method 2: ImageMagick (If Already Installed)
ImageMagick supports WebP output. If you already have it installed for other image tasks:
magick convert input.png -quality 80 output.webp
Batch:
magick mogrify -format webp -quality 80 *.png
Lossless:
magick convert input.png -define webp:lossless=true output.webp
ImageMagick's WebP support is solid but less feature-rich than cwebp for WebP-specific options. If you need fine-grained control over alpha compression or near-lossless mode, use cwebp. For straightforward conversion, either tool works.
browser-native processing engine also works:
browser-native processing engine -i input.png -c:v libwebp -quality 80 output.webp
browser-native processing engine requires the libwebp codec, which most Linux distros include by default.
Sell Custom Apparel — We Handle Printing & Free ShippingMethod 3: Browser Converter — No Terminal
If you prefer a GUI or want to avoid the terminal:
- Open the PNG to WebP converter in Firefox or Chrome
- Drag PNG files into the browser window
- Set quality (80 for lossy, 100 for lossless)
- Download individual files or the entire batch as ZIP
The browser tool shows before/after file sizes and processes everything locally — no server upload. For one-off conversions and smaller batches, it is often faster than setting up a terminal command. For large batches or automated workflows, the CLI tools are better.
Integrating WebP Conversion Into Build Pipelines
Linux developers often need WebP conversion as part of a build or deploy workflow. Common patterns:
Makefile rule:
%.webp: %.png cwebp -q 80 $< -o $@ webp: $(patsubst %.png,%.webp,$(wildcard images/*.png))
npm script (for Node.js projects):
"scripts": {
"images": "for f in src/images/*.png; do cwebp -q 80 \"$f\" -o \"dist/images/$(basename \"$f\" .png).webp\"; done"
}
Git pre-commit hook (auto-convert new PNGs):
#!/bin/sh for f in $(git diff --cached --name-only --diff-filter=A | grep '\.png$'); do cwebp -q 80 "$f" -o "$(echo "$f" | sed 's/\.png$/.webp/')" git add "$(echo "$f" | sed 's/\.png$/.webp/')" done
These integrations ensure every PNG added to the project automatically gets a WebP counterpart. For web projects, this eliminates the manual conversion step entirely and guarantees your site always serves optimized images.
For a complete guide to serving WebP on websites, see our WebP implementation guide.
PNG to WebP — Browser or Terminal, Both Free
Quality slider, batch support, transparency preserved. Works in Firefox and Chrome on any distro.
Open Free PNG to WebP ConverterFrequently Asked Questions
What is the best way to convert PNG to WebP on Linux?
cwebp is the gold standard: cwebp -q 80 input.png -o output.webp. For lossless: cwebp -lossless. ImageMagick and browser-native processing engine also work. For quick conversions without the terminal, a browser-based tool works in Firefox or Chrome.
How do I install cwebp on Ubuntu?
Run: sudo apt install webp. This installs both cwebp (encoder) and dwebp (decoder). On Fedora: sudo dnf install libwebp-tools. On Arch: sudo pacman -S libwebp.
How do I batch convert PNG to WebP on Linux?
With cwebp: for f in *.png; do cwebp -q 80 "$f" -o "$(basename "$f" .png).webp"; done. With ImageMagick: magick mogrify -format webp -quality 80 *.png. Both convert every PNG in the current directory.
Does cwebp preserve transparency?
Yes. cwebp preserves alpha channel transparency by default. Both lossy and lossless modes support transparent WebP output. You can control alpha channel quality separately with the -alpha_q flag.

