Baxter Hills

WebP Buster

Background

WebP is Google's new image format that promises better compression than PNG and JPEG. The only problem is, this new format has poor compatability with existing systems. When you download images from the internet these days, they often come in WebP format. This means you have to manually convert them to PNG or JPEG before you can edit or even view them.

This becomes incredibly annoying when you're downloading lots of images, and frustrating when you want to edit an image but discover it's a WebP file only after trying to open it.

So I wrote a tool to automatically convert WebP's to a format of your choice as they come in with the help of Python and filesystem monitoring for Windows and Linux systems.

Program Description

The main program allows you to monitor specific directories or all drives on your computer. It can also "flush out" existing WebP files in a directory, converting them all at once. The program is smart enough to skip system folders and temporary files, and it won't try to convert files that are too large.

I am using Python with the Pillow library for image processing and the Watchdog package for filesystem monitoring. The program runs in the background and watches for new WebP files being created anywhere on your computer. When it detects one, it immediately converts it to PNG format (or JPEG/BMP/TIFF if you prefer).

When a WebP file is detected, the program first verifies that it's a valid WebP file by checking its header structure. This prevents any false positives. It then uses Pillow to convert the image while preserving transparency where possible. For JPEG output, it automatically handles the conversion of transparent images by adding a white background.

To handle filesystem events safely, it uses exponential backoff when files are temporarily locked by other programs, and it carefully manages file handles to prevent any corruption. The program also includes detailed logging so you can see exactly what's happening and troubleshoot any issues.

Example

Flushing a directory
Monitoring All Drives

Configuration

The program uses a YAML configuration file that lets you customize various aspects:

All settings have sensible defaults, but you can easily change them by editing the config.yml file that's automatically created in at ~/Webp_Buster/ or at the program directory.

Checkout the GitHub project and start busting WebPs today!

Last modified: 06 February 2025