Skip to main content

filter · Image filters

Recompress PNG (recompress_png)

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

recompress_png re-encodes PNG images losslessly. The PNG optimizer re-encodes the image and keeps the result only when it is smaller, under the same ImageLimitOptimizedPercent margin as the other formats; a losing result is remembered. This filter never makes a PNG lossy: turning a photographic PNG into a JPEG or a WebP is the conversion filters’ decision, and when that decision does not apply or loses, the lossless re-encode this filter controls is what runs.

How it works

The recompression filters reduce image file size by re-encoding images at an optimal quality level. They preserve visual quality while removing encoding inefficiencies, and each one handles exactly the format its name says, so a format you do not want re-encoded can be turned off by name without touching the others.

How each format is recompressed

recompress_png is also the path a resized PNG takes, because resizing re-encodes the file. In OptimizeForBandwidth mode the smaller bytes replace the original response in place, with the URL unchanged. The filter is a CoreFilter through rewrite_images.

recompress_images is a convenience filter that enables recompress_jpeg, recompress_png, and recompress_webp together with convert_gif_to_png, convert_jpeg_to_progressive, convert_jpeg_to_webp, convert_png_to_jpeg, jpeg_subsampling, strip_image_color_profile, and strip_image_meta_data.

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

Recompression is lossy. Setting quality too low produces visible artifacts. The default values are conservative and safe for most content. Photographic content can tolerate lower quality than screenshots or text-heavy images.

Configuration

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

Apache

ModPagespeedEnableFilters recompress_png

nginx

pagespeed EnableFilters recompress_png;

IIS (pagespeed.config)

pagespeed EnableFilters recompress_png

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

ModPagespeedDisableFilters recompress_png   # Apache
pagespeed DisableFilters recompress_png;   # nginx
pagespeed DisableFilters recompress_png   # IIS
ParameterDefaultDescription
ImageRecompressionQuality85General quality level for recompressed images (-1 to 100; -1 uses source quality)
JpegRecompressionQuality-1JPEG-specific quality; -1 uses ImageRecompressionQuality
WebpRecompressionQuality80WebP quality level

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 recompress_png filter do?
recompress_png re-encodes PNG images losslessly. The PNG optimizer re-encodes the image and keeps the result only when it is smaller, under the same ImageLimitOptimizedPercent margin as the other formats; a losing result is remembered. This filter never makes a PNG lossy: turning a photographic PNG into a JPEG or a WebP is the conversion filters' decision, and when that decision does not apply or loses, the lossless re-encode this filter controls is what runs.
Is recompress_png enabled by default?
Yes. recompress_png 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 recompress_png?
Add ModPagespeedDisableFilters recompress_png on Apache or pagespeed DisableFilters recompress_png; on nginx. On IIS, add pagespeed DisableFilters recompress_png to pagespeed.config.

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

Search