Skip to main content
Docs menu

filter · Image filters

Convert PNG to JPEG (convert_png_to_jpeg)

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

convert_png_to_jpeg converts PNG images with no alpha channel (fully opaque) that the image analysis classifies as photographic to lossy WebP or JPEG, which is typically much smaller for photographic content.

How it works

Format conversion filters serve images in the most efficient format for each browser and image type:

  • 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). 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.
  • Part of OptimizeForBandwidth, the level that optimizes resources without changing their URLs.
  • Also switched on by recompress_images and rewrite_images.
  • Risk rating on these docs: Generally safe.

Risks

  • convert_png_to_jpeg drops the alpha channel on opaque PNGs. mod_pagespeed checks for alpha before converting, but semi-transparent pixels at the boundary may cause subtle edge artifacts.

Configuration

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

Apache

ModPagespeedEnableFilters convert_png_to_jpeg

nginx

pagespeed EnableFilters convert_png_to_jpeg;

IIS (pagespeed.config)

pagespeed EnableFilters convert_png_to_jpeg

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

ModPagespeedDisableFilters convert_png_to_jpeg   # Apache
pagespeed DisableFilters convert_png_to_jpeg;   # nginx
pagespeed DisableFilters convert_png_to_jpeg   # IIS
ParameterDefaultDescription
ProgressiveJpegMinBytes10240Minimum JPEG size before converting to progressive
WebpRecompressionQuality80Quality for lossy WebP conversion
WebpAnimatedRecompressionQuality70Quality for animated WebP conversion

Scoping, ForbidFilters and the thresholds filters read: Choosing filters.

Frequently asked questions

What does the convert_png_to_jpeg filter do?
convert_png_to_jpeg converts PNG images with no alpha channel (fully opaque) that the image analysis classifies as photographic to lossy WebP or JPEG, which is typically much smaller for photographic content.
Is convert_png_to_jpeg enabled by default?
Yes. convert_png_to_jpeg 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_png_to_jpeg?
Add ModPagespeedDisableFilters convert_png_to_jpeg on Apache or pagespeed DisableFilters convert_png_to_jpeg; on nginx. On IIS, add pagespeed DisableFilters convert_png_to_jpeg to pagespeed.config.

This page is drawn from the convert_png_to_jpeg entry on Image filters. Every filter in one table: PageSpeed filters.

Search