WebP Image Tools
WebP is an image format developed by Google that produces significantly smaller files than JPEG and PNG at equivalent visual quality. Lossless WebP images average 26% smaller than equivalent PNGs. Lossy WebP images average 25-34% smaller than equivalent JPEGs. For a self-hosted blog or website, the difference in page load times and storage costs is meaningful enough to be worth understanding.
Kubuntu handles WebP natively in Brave, Gwenview, and most other modern applications. The tools on this page are for working with WebP from the command line: converting existing images, optimising files for web use, and batch processing large collections.
Installation
The official WebP tools from Google:
sudo apt install webp
This installs cwebp (encoder), dwebp (decoder), vwebp (viewer), and gif2webp. Verify:
cwebp -version
For more comprehensive image manipulation including WebP support:
sudo apt install imagemagick
cwebp: encoding images to WebP
Basic conversion
# Convert a JPEG to WebP at default quality (75)
cwebp image.jpg -o image.webp
# Convert a PNG to WebP (lossless)
cwebp -lossless image.png -o image.webp
# Set quality level (0-100, default 75)
cwebp -q 85 image.jpg -o image.webp
# Show encoding statistics
cwebp -q 85 -v image.jpg -o image.webp
Useful options
# Resize while converting (width x height, 0 to preserve aspect ratio)
cwebp -resize 800 0 image.jpg -o image.webp
# Strip EXIF metadata (reduces file size, improves privacy)
cwebp -metadata none image.jpg -o image.webp
# Lossless compression with maximum compression effort
cwebp -lossless -z 9 image.png -o image.webp
# Near-lossless (visual lossless, smaller than true lossless)
cwebp -near_lossless 60 image.png -o image.webp
# Multi-threading for faster encoding
cwebp -mt -q 85 image.jpg -o image.webp
Batch conversion with find
Convert all JPEGs in a directory to WebP:
find ~/Pictures -name "*.jpg" -exec sh -c \
'cwebp -q 85 "$1" -o "${1%.jpg}.webp"' _ {} \;
Convert all PNGs to lossless WebP:
find ~/Pictures -name "*.png" -exec sh -c \
'cwebp -lossless "$1" -o "${1%.png}.webp"' _ {} \;
Blog image optimisation script
For preparing images for blog posts, a script that converts, strips metadata, and reports size savings:
cat > ~/.local/bin/webp-optimise << 'EOF'
#!/usr/bin/env bash
# Convert image to WebP and report size savings
if [ -z "$1" ]; then
echo "Usage: webp-optimise <image> [quality]"
exit 1
fi
INPUT="$1"
QUALITY="${2:-85}"
OUTPUT="${INPUT%.*}.webp"
ORIGINAL_SIZE=$(stat -c%s "$INPUT")
cwebp -q "$QUALITY" -metadata none "$INPUT" -o "$OUTPUT" -quiet
if [ $? -eq 0 ]; then
NEW_SIZE=$(stat -c%s "$OUTPUT")
SAVING=$(( (ORIGINAL_SIZE - NEW_SIZE) * 100 / ORIGINAL_SIZE ))
echo "Converted: $INPUT -> $OUTPUT"
echo "Original: $(numfmt --to=iec $ORIGINAL_SIZE)"
echo "WebP: $(numfmt --to=iec $NEW_SIZE)"
echo "Saving: ${SAVING}%"
else
echo "Conversion failed"
fi
EOF
chmod +x ~/.local/bin/webp-optimise
Use it:
webp-optimise ~/Pictures/photo.jpg
webp-optimise ~/Pictures/screenshot.png 90
dwebp: decoding WebP images
Convert WebP back to other formats when needed:
# Decode to PNG (lossless, preserves all data)
dwebp image.webp -o image.png
# Decode to PPM
dwebp image.webp -ppm -o image.ppm
# Show image information without decoding
dwebp -info image.webp
webpinfo: inspecting WebP files
# Show file structure and metadata
webpinfo image.webp
# Show summary only
webpinfo -summary image.webp
ImageMagick
ImageMagick handles WebP as one of its many supported formats and is useful for more complex operations:
# Convert any format to WebP
convert image.jpg -quality 85 image.webp
# Resize and convert in one step
convert image.jpg -resize 1200x -quality 85 image.webp
# Batch convert all JPEGs in current directory
for f in *.jpg; do
convert "$f" -quality 85 "${f%.jpg}.webp"
done
# Convert WebP to PNG
convert image.webp image.png
# Strip EXIF and convert
convert image.jpg -strip -quality 85 image.webp
# Create a WebP thumbnail
convert image.jpg -thumbnail 300x200 -quality 80 thumbnail.webp
Dolphin integration
Dolphin displays WebP thumbnails natively on Kubuntu 24.04, so browsing a directory of WebP files works without any additional configuration.
The right-click context menu in Dolphin includes an Open With option that lists Gwenview, which opens WebP files directly. For conversion, the Dolphin service menu can be extended to add right-click WebP conversion.
Create a Dolphin service menu for quick WebP conversion:
mkdir -p ~/.local/share/kservices5/ServiceMenus
cat > ~/.local/share/kservices5/ServiceMenus/convert-to-webp.desktop << 'EOF'
[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=image/jpeg;image/png;image/gif;
Actions=ConvertToWebP
[Desktop Action ConvertToWebP]
Name=Convert to WebP
Icon=image-x-generic
Exec=sh -c 'for f in %F; do cwebp -q 85 -metadata none "$f" -o "${f%.*}.webp"; done'
EOF
After creating the file, right-clicking on any JPEG, PNG, or GIF in Dolphin shows a Convert to WebP option.
Viewing WebP files
Gwenview opens WebP files directly:
gwenview image.webp
Brave also opens WebP files if you drag them into the browser window, which is useful for quickly checking the result of a conversion.
For the terminal, vwebp provides a simple viewer (requires a display):
vwebp image.webp
AVIF: the next format worth knowing
WebP is the current practical choice for web images. AVIF is the emerging successor, with even better compression. Support in Kubuntu is improving but not universal yet.
Install AVIF tools if needed:
sudo apt install libavif-apps
# Convert to AVIF
avifenc --quality 60 image.png image.avif
# Convert from AVIF
avifdec image.avif image.png
For now, WebP is the pragmatic choice for blog images and self-hosted web content. Check browser support for AVIF before using it on a public-facing site.
When converting images for a blog post, keep the original. WebP is a publication format, not an archival one. The original JPEG or PNG at full quality is the master; the WebP is the version served to readers.