Skip to main content

filter · Image filters

Convert GIF to PNG (convert_gif_to_png)

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

convert_gif_to_png converts non-animated GIF images to PNG, which uses better compression.

How it works

convert_gif_to_png re-encodes a non-animated GIF as PNG. Without this filter, and without one of the animated-format conversions or the low-resolution preview path that need the same decode, a GIF that is not resized passes through the module untouched: no other filter re-encodes it. A resized GIF is decoded and resized as a PNG, so with this filter on it ships as PNG (or, if photographic and the lossy conversions apply, as JPEG or WebP); it never goes back out as a GIF. The conversion is lossless in intent (a GIF’s at-most-256-color palette maps into PNG), and the result is kept only when it is smaller than the original GIF under ImageLimitOptimizedPercent. One non-obvious effect: the filter also unlocks lossy treatment of photographic GIFs, because the lossy decision path accepts a GIF only when it may first be treated as a PNG-style source. With the filter off, a photographic GIF is never turned into a JPEG or lossy WebP; it can still leave as lossless WebP or AVIF when those conversions are enabled, and otherwise stays a GIF. 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

The Image filters page lists no specific risks for this filter. If a page misbehaves with it, DisableFilters convert_gif_to_png turns it off for the scope you set it in.

Configuration

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

Apache

ModPagespeedEnableFilters convert_gif_to_png

nginx

pagespeed EnableFilters convert_gif_to_png;

IIS (pagespeed.config)

pagespeed EnableFilters convert_gif_to_png

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

ModPagespeedDisableFilters convert_gif_to_png   # Apache
pagespeed DisableFilters convert_gif_to_png;   # nginx
pagespeed DisableFilters convert_gif_to_png   # 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_gif_to_png filter do?
convert_gif_to_png converts non-animated GIF images to PNG, which uses better compression.
Is convert_gif_to_png enabled by default?
Yes. convert_gif_to_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 convert_gif_to_png?
Add ModPagespeedDisableFilters convert_gif_to_png on Apache or pagespeed DisableFilters convert_gif_to_png; on nginx. On IIS, add pagespeed DisableFilters convert_gif_to_png to pagespeed.config.

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

Search