Convert JPEG images to WebP entirely in the browser with the Canvas API. WebP often shrinks photographic JPEGs by roughly 25–35% at similar perceived quality, which helps page-weight budgets without uploading files to a server.
How it works
A local .jpg / .jpeg file is decoded, drawn to an off-screen canvas, and exported with toBlob('image/webp') (or equivalent data-URL encoding) at a quality factor you choose between 0 and 1. Higher quality keeps more detail and produces larger WebP files; lower quality favors size. Processing uses the browser’s built-in WebP encoder.
When to use it
- Prepare hero or blog photos for sites that serve WebP
- A/B test quality settings before a batch conversion pipeline
- Convert a single asset when desktop converters are unavailable
Limitations
Requires a browser with WebP encode support. EXIF orientation, ICC profiles, and metadata are typically stripped. Progressive JPEG structure is flattened. Extremely large images may hit canvas dimension or memory limits.
Example
A 1200×800 JPEG of about 420 KB at quality 0.8 often becomes a WebP near 280–320 KB with little visible difference on screen; quality 0.5 may drop below 200 KB with softer fine detail.