All posts
PNG to WebP via CLI
Convert PNG to WebP with cwebp — lossy or lossless.
Open online converterPackages to install
Install the webp package. cwebp accepts both PNG and JPEG.
webp
sudo apt-get update
sudo apt-get install -y webpHow to run the command
For the web, cwebp -q 90 is typical. Use -lossless when you need an exact pixel copy.
cwebp -q 90 photo.png -o photo.webpDockerfile example
Build a minimal Ubuntu image with the required packages and run the conversion inside the container.
FROM ubuntu:24.04
RUN apt-get update && \
apt-get install -y --no-install-recommends \
webp && \
rm -rf /var/lib/apt/lists/*
WORKDIR /work
docker build -t png-to-webp .
docker run --rm -v "$PWD:/work" -w /work png-to-webp \
cwebp -q 90 photo.png -o photo.webpExample commands
Run these locally after installing the packages, or inside the container from the Dockerfile.
cwebp -q 90 photo.png -o photo.webpcwebp -lossless photo.png -o photo.webp