Skip to main content

filter · Image filters

Recompress images (recompress_images)

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

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.

What it switches on

recompress_images is a compound name. Enabling it enables these 10 filters; each can be disabled on its own.

How it works

How each format is recompressed

recompress_jpeg re-encodes JPEG images that reach it. It runs after the conversion candidates: a JPEG that was not converted to WebP or AVIF for this request is re-encoded at JpegRecompressionQuality, which defaults to -1, meaning it follows ImageRecompressionQuality (default 85). Only when ImageRecompressionQuality is itself -1 does the module keep the source file’s own quality.

recompress_jpeg keeps a re-encode only when it is smaller than the original by the margin ImageLimitOptimizedPercent sets (default 100: any reduction at all), and a losing re-encode is remembered so the same JPEG is not re-encoded on every request. The filter is a CoreFilter through rewrite_images and also part of OptimizeForBandwidth; disabling it by name while keeping the compound on leaves the other formats recompressing.

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.

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_webp re-encodes WebP images the page already serves, at WebpRecompressionQuality (default 80). It does not create WebP; converting JPEG or PNG sources to WebP is the conversion filters’ job. Animated WebP is never recompressed, and there is no fallback conversion of WebP to JPEG for browsers without WebP support: such sources are left alone rather than transcoded.

recompress_webp keeps a re-encode only when it is smaller under ImageLimitOptimizedPercent, and a losing result is remembered. A small-screen client gets a lower quality still: WebpRecompressionQualityForSmallScreens (default 70) applies to the requests the module classifies as small-screen. The filter is a CoreFilter through rewrite_images and part of OptimizeForBandwidth.

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.
  • 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_images

nginx

pagespeed EnableFilters recompress_images;

IIS (pagespeed.config)

pagespeed EnableFilters recompress_images

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

ModPagespeedDisableFilters recompress_images   # Apache
pagespeed DisableFilters recompress_images;   # nginx
pagespeed DisableFilters recompress_images   # IIS
ModPagespeedEnableFilters recompress_images
# Or individually:
ModPagespeedEnableFilters recompress_jpeg,recompress_png,recompress_webp
pagespeed EnableFilters recompress_images;
# Or individually:
pagespeed EnableFilters recompress_jpeg,recompress_png,recompress_webp;
ParameterDefaultDescription
ImageRecompressionQuality85General quality level for recompressed images (-1 to 100; -1 uses source quality)
JpegRecompressionQuality-1JPEG-specific quality; -1 uses ImageRecompressionQuality
WebpRecompressionQuality80WebP quality level
ModPagespeedImageRecompressionQuality 85
ModPagespeedJpegRecompressionQuality 75
pagespeed ImageRecompressionQuality 85;
pagespeed JpegRecompressionQuality 75;

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

Frequently asked questions

What does the recompress_images filter do?
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.
Is recompress_images enabled by default?
Yes. recompress_images 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_images?
Add ModPagespeedDisableFilters recompress_images on Apache or pagespeed DisableFilters recompress_images; on nginx. On IIS, add pagespeed DisableFilters recompress_images to pagespeed.config.

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

Search