filter · Image filters
Lossless WebP (convert_to_webp_lossless)
- Category:
- Image
- CoreFilters:
- Yes
- OptimizeForBandwidth:
- No
- Risk:
- Test first
convert_to_webp_lossless serves PNG and GIF images that the image analysis classifies as graphics (not photographic) as lossless WebP, which preserves every pixel. It does not make photographic PNGs lossless: those take the lossy path of convert_png_to_jpeg when that filter is on (the default). Without it, a PNG graphic stays PNG and a GIF graphic becomes PNG (with convert_gif_to_png on, the default).
How it works
A CoreFilter, enabled by default through rewrite_images.
convert_png_to_jpeg turns a PNG into a JPEG only when the module’s image analysis says the file is photographic, meaning not sensitive to compression noise, and it has no transparent pixels. The analysis is what protects flat graphics: a logo or a diagram analyzes as non-photographic and keeps its PNG. On a photographic PNG without transparency the filter authorizes lossy encoding, and the format that ships depends on the browser: when the request prefers WebP and convert_jpeg_to_webp is on, the file becomes WebP rather than JPEG; otherwise it is re-encoded as JPEG at the JPEG quality setting. A PNG with transparency is never made a JPEG. The analysis is a heuristic, and a large, smooth photo (soft sky, landscape, a photo re-saved as PNG) can be classified as a graphic. It then takes the lossless path of convert_to_webp_lossless and ships as lossless WebP, which is much larger than a lossy encode. For photographic images, serve the source as JPEG, which the analysis always treats as photographic, or keep the original URL (ImagePreserveURLs on, see ImagePreserveURLs, or data-pagespeed-no-transform on a single <img>) so the optimizer worker negotiates AVIF or lossy WebP, which gives smaller files. The cost is that the module’s image inlining, resizing and lazy loading no longer apply to those images; the format rule is described in Image format and the Accept header. The converted file is kept only when it is smaller (ImageLimitOptimizedPercent), and a PNG carrying a C2PA content-credentials manifest is left untouched so its provenance chain survives. The filter runs in CoreFilters through rewrite_images.
When to use it
- In CoreFilters, the default RewriteLevel: it runs unless you disable it.
- Also switched on by
rewrite_images. - Risk rating on these docs: Test first.
Risks
convert_to_webp_losslessapplies to PNGs and GIFs the image analysis classes as graphics. A large, smooth photograph can be classed as a graphic and then served as lossless WebP, which can be much larger than a lossy encoding. Serve photographs as JPEG, or keep the original URL (ImagePreserveURLs on, ordata-pagespeed-no-transform) so the optimizer worker negotiates a lossy format.
Configuration
Enable it in the module configuration, at server, virtual-host or location scope:
Apache
ModPagespeedEnableFilters convert_to_webp_losslessnginx
pagespeed EnableFilters convert_to_webp_lossless;IIS (pagespeed.config)
pagespeed EnableFilters convert_to_webp_losslessIt is on by default under CoreFilters; to turn it off:
ModPagespeedDisableFilters convert_to_webp_lossless # Apache
pagespeed DisableFilters convert_to_webp_lossless; # nginx
pagespeed DisableFilters convert_to_webp_lossless # IIS| Parameter | Default | Description |
|---|---|---|
ProgressiveJpegMinBytes | 10240 | Minimum JPEG size before converting to progressive |
WebpRecompressionQuality | 80 | Quality for lossy WebP conversion |
WebpAnimatedRecompressionQuality | 70 | Quality for animated WebP conversion |
On the worker
The worker runs its own pipeline, configured by flags. Its equivalent of this
filter is the
image pipeline
transform. Always-on baseline under pagespeed on;; there is no per-transform off switch.
Scoping, ForbidFilters and the thresholds filters read:
Choosing filters.
Frequently asked questions
- What does the convert_to_webp_lossless filter do?
convert_to_webp_losslessserves PNG and GIF images that the image analysis classifies as graphics (not photographic) as lossless WebP, which preserves every pixel. It does not make photographic PNGs lossless: those take the lossy path ofconvert_png_to_jpegwhen that filter is on (the default). Without it, a PNG graphic stays PNG and a GIF graphic becomes PNG (withconvert_gif_to_pngon, the default).- Is convert_to_webp_lossless enabled by default?
- Yes.
convert_to_webp_losslessis in CoreFilters, the default RewriteLevel, so it runs unless you turn it off withDisableFilters. - How do I turn off convert_to_webp_lossless?
- Add
ModPagespeedDisableFilters convert_to_webp_losslesson Apache orpagespeed DisableFilters convert_to_webp_lossless;on nginx. On IIS, addpagespeed DisableFilters convert_to_webp_losslessto pagespeed.config.
Related filters
- convert_gif_to_png — Convert GIF to PNG
- convert_jpeg_to_progressive — Progressive JPEG
- convert_jpeg_to_webp — Convert JPEG to WebP
- convert_png_to_jpeg — Convert PNG to JPEG
- convert_to_webp_animated — Animated WebP
- convert_jpeg_to_avif — Convert JPEG to AVIF
- convert_to_avif_animated — Animated AVIF
- convert_to_avif_lossless — Lossless AVIF
This page is drawn from the convert_to_webp_lossless entry on Image filters. Every filter in one table: PageSpeed filters.