# Convert JPEG to WebP (convert_jpeg_to_webp)

Converts JPEG to WebP for capable browsers. The convert_jpeg_to_webp filter: what it does, its risks and the Apache, nginx and IIS directives.

Canonical URL: https://modpagespeed.com/docs/filters/convert_jpeg_to_webp/

- Category: Image
- CoreFilters: Yes
- OptimizeForBandwidth: Yes
- Risk: Generally safe

**`convert_jpeg_to_webp`** serves WebP versions of JPEG images to browsers that send `Accept: image/webp`. The original JPEG is preserved for other browsers.

## How it works

`convert_jpeg_to_webp` is the member of the family with the widest reach, because JPEG is where photographic weight usually sits. For a WebP-capable request, the filter encodes a WebP candidate at `WebpRecompressionQuality` (default 80) and keeps it when it is smaller than the original JPEG. WebP-capable requests (by `Accept: image/webp` or a known user agent) get HTML pointing at a `.webp` URL; others get the JPEG URL, so the HTML differs per browser; a CDN caching rewritten HTML must not share it across browsers. The filter runs in CoreFilters through `rewrite_images` and is listed in OptimizeForBandwidth, but in that level's in-place mode no WebP is selected.

`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 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.
- Part of OptimizeForBandwidth, the level that optimizes resources without changing their URLs.
- Also switched on by [`recompress_images`](https://modpagespeed.com/docs/filters/recompress_images/) and [`rewrite_images`](https://modpagespeed.com/docs/filters/rewrite_images/).
- Risk rating on these docs: **Generally safe**.

## Risks

- `convert_jpeg_to_webp` decides per request, so the rewritten HTML names a `.webp` image for some browsers and a JPEG for others. A CDN or proxy that caches the HTML must not serve one browser's copy to another; test with your CDN configuration.

## Configuration

Enable it in the module configuration, at server, virtual-host or location scope:

**Apache**

```apache
ModPagespeedEnableFilters convert_jpeg_to_webp
```

**nginx**

```nginx
pagespeed EnableFilters convert_jpeg_to_webp;
```

**IIS (pagespeed.config)**

```text
pagespeed EnableFilters convert_jpeg_to_webp
```

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

```text
ModPagespeedDisableFilters convert_jpeg_to_webp   # Apache
pagespeed DisableFilters convert_jpeg_to_webp;   # nginx
pagespeed DisableFilters convert_jpeg_to_webp   # 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_jpeg_to_webp filter do?**

`convert_jpeg_to_webp` serves WebP versions of JPEG images to browsers that send `Accept: image/webp`. The original JPEG is preserved for other browsers.

**Is convert_jpeg_to_webp enabled by default?**

Yes. `convert_jpeg_to_webp` is in CoreFilters, the default RewriteLevel, so it runs unless you turn it off with `DisableFilters`. It is also part of the OptimizeForBandwidth level.

**How do I turn off convert_jpeg_to_webp?**

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

## Related filters

- [`convert_jpeg_to_avif`](https://modpagespeed.com/docs/filters/convert_jpeg_to_avif/): Convert JPEG to AVIF
- [`rewrite_images`](https://modpagespeed.com/docs/filters/rewrite_images/): Optimize images
- [`recompress_jpeg`](https://modpagespeed.com/docs/filters/recompress_jpeg/): Recompress JPEG
- [`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/filters/convert_jpeg_to_progressive/): Progressive JPEG
- [`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/filters/convert_to_webp_animated/): Animated WebP
- [`convert_to_webp_lossless`](https://modpagespeed.com/docs/filters/convert_to_webp_lossless/): Lossless WebP

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