Shrinking Blog Post Images using WebP
In today’s internet, speed is everything. Whether you’re writing a personal blog or running a content-heavy website, optimizing the size of your images can make a huge difference:
- 🚀 Faster Page Loads: Smaller images mean quicker page rendering. This is critical for improving user experience, especially for mobile visitors with slower connections.
- 📱 Better Mobile Performance: Most internet traffic now comes from smartphones. These devices often operate under bandwidth constraints, so smaller images = happier users.
- 🔍 SEO Boost: Search engines like Google factor in page speed. Optimized images help you rank higher.
- 🧊 Reduced Hosting Costs: Smaller files consume less bandwidth and storage over time.
WebP is a modern image format developed by Google that provides superior compression—lossy and lossless—while maintaining high visual quality. Let’s explore how to use the cwebp
command-line tool to convert your images.
🔧 Installing cwebp
on Your System
cwebp
is a command line tool which can be installed Linux, macOS and even Windows. Let’s have a look how you can install cwebp
on your system.
🐧 Linux (Debian/Ubuntu)
1
sudo apt install webp
This installs both cwebp
and dwebp
(the decoder).
🍏 macOS (Using Homebrew)
1
brew install webp
Homebrew will fetch and install the latest stable version.
🪟 Windows
- Go to the official WebP download page.
- Download the precompiled binary for Windows.
- Extract the archive and add the folder containing
cwebp.exe
to your system’sPATH
environment variable for global access.
You can test that the tool is installed with:
1
cwebp -version
🛠️ Converting Images with cwebp
The cwebp
tool allows fine-grained control over image quality and compression. Here’s how to convert a JPEG or PNG to WebP:
1
cwebp input.jpg -o output.webp
This basic command uses default settings. Want more control? Here are a few helpful options:
🔧 Set Quality (0–100):
1
cwebp -q 80 input.png -o output.webp
A lower value results in a smaller file, but lower quality. 75 is default and 80 is usually a good balance of size and quality.
🗃 Compression method (0 - 6):
1
cwebp -m 5 input.png -o output.webp
This option is a trade off compression speed and quality. 0 is the fastest and 6 the best quality - 4 is the default value.
🖼️ Lossless mode:
1
cwebp -lossless input.png -o output.webp
You can even adjust the compression mode for lossless (0 is fastest whereas 9 is slowest but best):
1
cwebp -z 6 input.png -o output.webp
🧪 Preview the Compression Ratio:
1
cwebp -q 75 input.jpg -o output.webp -print_psnr
🌀 Batch Convert Images (Bash Loop Example):
1 2 3
for i in *.jpg; do cwebp -m 6 -q 80 "$i" -o "${i%.jpg}.webp" done
This loop converts all
.jpg
files in a folder to.webp
.
🧩 Integrating WebP into Your Blog
Once you’ve converted your images:
- Replace
<img src="image.jpg">
with<img src="image.webp">
in your blog HTML. - ✅ Ensure your blog host supports WebP (most modern platforms do).
- 🧠 Consider providing a fallback using the
<picture>
element:
1
2
3
4
<picture>
<source srcset="image.webp" type="image/webp">
<img src="image.jpg" alt="Example image">
</picture>
This ensures backward compatibility with older browsers.
🧠 Final Thoughts
Using cwebp
to convert your blog images to WebP is a quick win for speed, SEO, and user experience. It’s a small step with big returns — especially as mobile browsing continues to dominate. Whether you’re using a full CMS or writing static markdown posts, smaller images help everyone load your content faster and more efficiently.
Try converting one image today and see the difference in size. You’ll likely be surprised how much space you can save!