# Lossless WebP (convert_to_webp_lossless)

Converts PNG/GIF graphics (not photos) to lossless WebP. The convert_to_webp_lossless filter: what it does, its risks and the directives.

Canonical URL: https://modpagespeed.com/docs/filters/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`](https://modpagespeed.com/docs/configuration/#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](https://modpagespeed.com/docs/cdn-integration/#image-format-negotiation). 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`](https://modpagespeed.com/docs/filters/rewrite_images/).
- Risk rating on these docs: **Test first**.

## Risks

- `convert_to_webp_lossless` applies 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`, or `data-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**

```apache
ModPagespeedEnableFilters convert_to_webp_lossless
```

**nginx**

```nginx
pagespeed EnableFilters convert_to_webp_lossless;
```

**IIS (pagespeed.config)**

```text
pagespeed EnableFilters convert_to_webp_lossless
```

It is on by default under CoreFilters; to turn it off:

```text
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](https://modpagespeed.com/docs/worker-configuration/#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](https://modpagespeed.com/docs/filter-selection/).

## Frequently asked questions

**What does the convert_to_webp_lossless filter do?**

`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).

**Is convert_to_webp_lossless enabled by default?**

Yes. `convert_to_webp_lossless` is in CoreFilters, the default RewriteLevel, so it runs unless you turn it off with `DisableFilters`.

**How do I turn off convert_to_webp_lossless?**

Add `ModPagespeedDisableFilters convert_to_webp_lossless` on Apache or `pagespeed DisableFilters convert_to_webp_lossless;` on nginx. On IIS, add `pagespeed DisableFilters convert_to_webp_lossless` to pagespeed.config.

## Related filters

- [`convert_gif_to_png`](https://modpagespeed.com/docs/filters/convert_gif_to_png/): Convert GIF to PNG
- [`convert_jpeg_to_progressive`](https://modpagespeed.com/docs/image-filters/#convert_jpeg_to_progressive): Progressive JPEG
- [`convert_jpeg_to_webp`](https://modpagespeed.com/docs/filters/convert_jpeg_to_webp/): Convert JPEG to WebP
- [`convert_png_to_jpeg`](https://modpagespeed.com/docs/filters/convert_png_to_jpeg/): Convert PNG to JPEG
- [`convert_to_webp_animated`](https://modpagespeed.com/docs/image-filters/#convert_to_webp_animated): Animated WebP
- [`convert_jpeg_to_avif`](https://modpagespeed.com/docs/image-filters/#convert_jpeg_to_avif): Convert JPEG to AVIF
- [`convert_to_avif_animated`](https://modpagespeed.com/docs/image-filters/#convert_to_avif_animated): Animated AVIF
- [`convert_to_avif_lossless`](https://modpagespeed.com/docs/image-filters/#convert_to_avif_lossless): Lossless AVIF

This page is drawn from the [convert_to_webp_lossless entry on Image filters](https://modpagespeed.com/docs/image-filters/#convert_to_webp_lossless). Every filter in one table: [PageSpeed filters](https://modpagespeed.com/docs/filters/).
