Convert all your images to WebP instantly for free on Linux

By · Published: · Updated:

“Convert all your images to WebP for free on Linux” cover with a laptop editing a photo and a basicseo.net search result

Quick answer: You don’t need Photoshop, an expensive converter or a paid online service to switch your images to WebP. On Ubuntu and most Linux distributions, five free command-line tools (cwebp, ffmpeg, libvips, ImageMagick and gif2webp) can convert hundreds of JPG, PNG and GIF files in seconds. Install one with apt, run one command inside your folder, and your images get 25–34% lighter than JPEG at the same visual quality, with GIFs shrinking even more.

Why your images should be WebP

Images are usually the heaviest part of a web page, so they have the biggest effect on how fast it loads. That matters for your visitors, especially on mobile data, and for SEO: page speed is part of Google’s Core Web Vitals, and the largest image on screen is often what decides your LCP (Largest Contentful Paint).

WebP is an image format created by Google to solve exactly that. According to Google’s own measurements:

  • Lossy WebP images are 25–34% smaller than comparable JPEG images at the same visual quality.
  • Lossless WebP images are 26% smaller than PNGs.
  • Transparency costs only about 22% extra bytes, versus the huge PNGs you’d need otherwise.
  • Animated GIFs converted to lossy WebP are 64% smaller on average.

It also does everything in a single format: lossy and lossless compression, full transparency and animation. And browser support is no longer an issue: WebP works in Chrome, Safari, Firefox, Edge and Opera, about 97% of users worldwide according to Can I Use.

Lighter images are one of the basic SEO recommendations with the most impact. Don’t forget descriptive alt text when you swap them in.

The problems with JPG, JPEG, PNG and GIF

FormatCompressionTransparencyAnimationMain problem
JPG / JPEGLossy onlyNoNoHeavier than WebP at the same quality; loses quality every time it’s re-saved
PNGLossless onlyYesNoHuge files for photos
GIFLossless, 256 colorsOn/off onlyYesVery heavy and limited to 256 colors
WebPLossy and losslessYes (full alpha)YesNot supported by very old browsers like Internet Explorer

JPG and JPEG

JPG and JPEG are the same format; the shorter extension comes from old systems that only allowed three characters. It was designed in the early 1990s and it shows: at the same visual quality it’s noticeably heavier than WebP, it can’t do transparency, and it’s lossy only, so every time you edit and save a JPEG it loses a bit more detail. Around sharp edges and text you’ll also see blocky “artifacts”.

PNG

PNG is lossless and supports transparency, which makes it great for logos and screenshots, but terrible for photos. A photo saved as PNG can easily weigh several megabytes, many times the same picture as a JPEG or WebP. Lots of websites end up serving huge PNGs simply because that’s what the designer exported.

GIF

GIF is from 1987. It’s limited to 256 colors, its transparency is all-or-nothing (no smooth edges), and animated GIFs are enormous for what they show. A few seconds of animation can weigh several megabytes, which is why converting GIFs gives some of the biggest savings of all.

No Photoshop, no paid software, no online converters

You don’t need Photoshop, an expensive conversion program or a subscription to an online tool. Every tool in this guide is free and open source, and it’s already in Ubuntu’s official repositories.

  • Hundreds of images at once: one command converts a whole folder, including subfolders, at no cost.
  • No upload limits or watermarks: online converters often cap the number or size of files, or charge for “pro” features.
  • Your files never leave your computer: nothing is uploaded to a third-party server, which matters for client work and private photos.
  • Repeatable: save the command in a script and run it again every time you add new images.

Before you start

All commands below are run from inside the folder that holds your images (cd ~/Pictures/my-site, for example). A few notes so nothing surprises you:

  • shopt -s nullglob nocaseglob makes the loops case-insensitive (so .JPG and .jpg both match) and skips patterns that find no files. It only lasts for your current terminal session.
  • "${f%.*}.webp" means “same file name, with a .webp extension”: photo.jpg becomes photo.webp. Names with spaces work fine.
  • Your original files are kept. Every command writes new .webp files next to them (or in a separate folder, where noted).
  • If two files share a name with different extensions (photo.jpg and photo.png), they would both become photo.webp. Rename one first.
  • Quality 75–85 is the sweet spot for photos on the web. Go higher only if you notice artifacts.

Working on images you can’t replace? Make a copy of the folder first, just in case.

The top 5 command-line tools to convert images to WebP on Ubuntu

Here are the five best command-line tools for Ubuntu, ranked by efficiency, speed and the specific job each one does best. Under each one you’ll find the commands to convert every image in a folder.

1. cwebp (the official standard)

Developed by Google, cwebp is the best all-round tool. As the official encoder, it’s the first to get every improvement to the format, and it gives you the most precise control over quality, metadata and color profiles.

  • Install: sudo apt install webp
  • Best for: perfect compression of static JPEGs and PNGs for the web.

Convert every JPG, JPEG and PNG in the current folder (keeping the color profile):

shopt -s nullglob nocaseglob
for f in *.jpg *.jpeg *.png; do
  cwebp -quiet -q 80 -metadata icc "$f" -o "${f%.*}.webp"
done

Logos, icons and screenshots look best with lossless compression:

shopt -s nullglob nocaseglob
for f in *.png; do
  cwebp -quiet -lossless "$f" -o "${f%.*}.webp"
done

Include every subfolder, and use all your CPU cores to go faster:

find . -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' \) -print0 \
  | xargs -0 -P "$(nproc)" -I{} sh -c 'cwebp -quiet -q 80 "
" -o "${1%.*}.webp"' _ {}

2. ffmpeg (the animation master)

ffmpeg is the ultimate tool for animated GIFs. While other commands can produce huge or broken animated WebP files, ffmpeg makes the most of the format’s compression between frames, cutting heavy GIFs down dramatically (Google measured an average 64% saving, and large GIFs often shrink much more).

  • Install: sudo apt install ffmpeg
  • Best for: converting heavy GIFs to animated WebP and extracting frames from video.

Convert every GIF in the folder to an animated WebP that loops forever:

shopt -s nullglob nocaseglob
for f in *.gif; do
  ffmpeg -hide_banner -loglevel error -n -i "$f" \
    -c:v libwebp_anim -lossless 0 -q:v 75 -loop 0 -an "${f%.*}.webp"
done

ffmpeg also converts static images (-n skips files that already exist):

shopt -s nullglob nocaseglob
for f in *.jpg *.jpeg *.png; do
  ffmpeg -hide_banner -loglevel error -n -i "$f" -c:v libwebp -q:v 80 "${f%.*}.webp"
done

Extract one WebP frame per second from a video (great for thumbnails):

ffmpeg -i video.mp4 -vf fps=1 -c:v libwebp -q:v 80 frame_%04d.webp

3. vips / libvips (the unbeatable sprinter)

libvips is an optimized processing engine that works on the image in small pieces instead of loading the whole thing into RAM. It’s several times faster than ImageMagick (in the benchmarks published by sharp, which is built on libvips, it runs roughly 4.5 to 9 times faster) and uses a fraction of the memory.

  • Install: sudo apt install libvips-tools
  • Best for: huge images (4K, maps, high-resolution photos) or batches of thousands of files without freezing your computer.

Convert every image in the folder (strip removes metadata such as EXIF and GPS location):

shopt -s nullglob nocaseglob
for f in *.jpg *.jpeg *.png *.tif *.tiff; do
  vips copy "$f" "${f%.*}.webp[Q=80,strip]"
done

Resize and convert in one step: images larger than 1920 px are shrunk (smaller ones are left alone) and saved to a resized folder:

shopt -s nullglob nocaseglob
mkdir -p resized
vipsthumbnail *.jpg *.jpeg *.png --size "1920x1920>" -o "resized/%s.webp[Q=80]"

4. ImageMagick (mogrify / magick)

The Swiss Army knife of the terminal. It isn’t the fastest and it doesn’t compress the best, but its mogrify command converts whole folders in a single line, with no Bash loops needed.

  • Install: sudo apt install imagemagick
  • Best for: quick bulk changes on the fly.

Convert every image in the folder (with -format, mogrify writes new .webp files and keeps the originals):

shopt -s nullglob nocaseglob
mogrify -format webp -quality 80 *.jpg *.jpeg *.png

Save the results in a separate webp folder instead, and use lossless compression for PNG graphics:

shopt -s nullglob nocaseglob
mkdir -p webp
mogrify -path webp -format webp -quality 80 *.jpg *.jpeg
mogrify -path webp -format webp -define webp:lossless=true *.png

Ubuntu 24.04 ships ImageMagick 6, where the commands are mogrify and convert. On ImageMagick 7 put magick in front: magick mogrify -format webp ….

5. gif2webp (the lightweight alternative)

Another official tool from Google’s WebP package. If you need to turn GIFs into animated WebP but don’t want to install the huge ffmpeg suite, this dedicated utility does the job natively and with almost no footprint.

  • Install: it comes with sudo apt install webp
  • Best for: direct GIF to WebP conversion without any video dependencies.

Convert every GIF in the folder (-mixed picks lossy or lossless for each frame, whichever is smaller; -m 6 compresses harder):

shopt -s nullglob nocaseglob
for f in *.gif; do
  gif2webp -quiet -q 80 -m 6 -mixed "$f" -o "${f%.*}.webp"
done

Quick comparison

ToolInstallBest forAnimated GIFs
cwebpsudo apt install webpBest quality/size for JPG and PNGNo (use gif2webp)
ffmpegsudo apt install ffmpegAnimations and video framesYes, best results
libvipssudo apt install libvips-toolsSpeed, huge images, thousands of filesYes
ImageMagicksudo apt install imagemagickOne-line bulk conversionYes
gif2webpIncluded in webpLightweight GIF conversionYes

Convert a whole folder in one go

This small script combines the two official tools: cwebp for photos and graphics, gif2webp for animations. It goes through every subfolder and skips images that were already converted, so you can run it again whenever you add new files.

#!/usr/bin/env bash
# webpify.sh: convert every JPG, PNG and GIF in a folder (and subfolders) to WebP
# Usage: bash webpify.sh /path/to/images
set -euo pipefail
cd "${1:-.}"

find . -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' -o -iname '*.gif' \) -print0 |
while IFS= read -r -d '' f; do
  out="${f%.*}.webp"
  [ -e "$out" ] && continue
  case "${f,,}" in
    *.gif) gif2webp -quiet -q 80 -m 6 -mixed "$f" -o "$out" ;;
    *.png) cwebp -quiet -lossless "$f" -o "$out" ;;
    *)     cwebp -quiet -q 80 -metadata icc "$f" -o "$out" ;;
  esac
  echo "✔ $out"
done

Then compare how much space you saved:

shopt -s nullglob nocaseglob
du -ch *.jpg *.jpeg *.png *.gif | tail -1
du -ch *.webp | tail -1

PNGs here use lossless mode, ideal for logos and screenshots. If your PNGs are actually photos, change that line to cwebp -quiet -q 80 and they’ll shrink much more.

Use your new WebP images on your website

Upload the .webp files and update your image references. With 97% of browsers supporting WebP, a plain <img> is enough for most sites. Always include width, height and a descriptive alt:

<img src="/images/team-photo.webp" alt="Our team at the Tijuana office" width="1200" height="800" loading="lazy">

If you need to support very old browsers, use <picture> with your original file as a fallback:

<picture>
  <source srcset="/images/team-photo.webp" type="image/webp">
  <img src="/images/team-photo.jpg" alt="Our team at the Tijuana office" width="1200" height="800" loading="lazy">
</picture>

FAQ

Will converting to WebP lower the quality of my images?

Not visibly at quality 75–85, which is what most websites use. If you need pixel-perfect copies (logos, screenshots), use lossless mode: the image stays identical and the file is still smaller than the PNG.

Is JPG different from JPEG?

No. They are the same format; JPG is just the three-letter version of the extension. The commands in this guide handle both.

Does WebP work in every browser?

It works in Chrome, Safari, Firefox, Edge and Opera, about 97% of users worldwide. Only very old browsers such as Internet Explorer don’t support it; use <picture> with a fallback if you still need them.

Should I delete my original images?

Keep them in a backup. WebP is perfect for publishing, but your originals are the best source if you ever need to edit, re-export or print.

Do these tools work outside Ubuntu?

Yes. On Debian and Linux Mint the same apt commands work. On other distributions look for the webp (or libwebp), ffmpeg, vips and ImageMagick packages in your package manager, and on macOS you can install them with Homebrew (for example, brew install webp).

Sources

Leer en español: Convierte todas tus imágenes a WebP al instante y gratis en Linux