All posts

JPEG to WebP via CLI

Encode JPEG as WebP with cwebp at quality 90.

Open online converter

Packages to install

The webp package installs cwebp for encoding and dwebp for decoding.

webp
apt install
sudo apt-get update
sudo apt-get install -y webp

How to run the command

cwebp -q 90 reads a JPEG and writes WebP to the -o path. Quality 90 is a solid size/quality trade-off.

cwebp
cwebp -q 90 photo.jpg -o photo.webp

Dockerfile example

Build a minimal Ubuntu image with the required packages and run the conversion inside the container.

Dockerfile
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 && docker run
docker build -t jpeg-to-webp .
docker run --rm -v "$PWD:/work" -w /work jpeg-to-webp \
  cwebp -q 90 photo.jpg -o photo.webp

Example commands

Run these locally after installing the packages, or inside the container from the Dockerfile.

Example 1
cwebp -q 90 photo.jpg -o photo.webp
Example 2
cwebp -q 80 photo.jpeg -o photo.webp