# Convert GIF to PNG (convert_gif_to_png)

Converts GIF to PNG. How the mod_pagespeed convert_gif_to_png filter works, when to use it, its risks and the Apache, nginx and IIS directives.

Canonical URL: https://modpagespeed.com/docs/filters/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`](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

The [Image filters](https://modpagespeed.com/docs/image-filters/#convert_gif_to_png) 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**

```apache
ModPagespeedEnableFilters convert_gif_to_png
```

**nginx**

```nginx
pagespeed EnableFilters convert_gif_to_png;
```

**IIS (pagespeed.config)**

```text
pagespeed EnableFilters convert_gif_to_png
```

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

```text
ModPagespeedDisableFilters convert_gif_to_png   # Apache
pagespeed DisableFilters convert_gif_to_png;   # nginx
pagespeed DisableFilters convert_gif_to_png   # 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               |

Scoping, `ForbidFilters` and the thresholds filters read: [Choosing filters](https://modpagespeed.com/docs/filter-selection/).

## 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.

## Related filters

- [`convert_jpeg_to_progressive`](https://modpagespeed.com/docs/filters/convert_jpeg_to_progressive/): Progressive JPEG
- [`convert_jpeg_to_webp`](https://modpagespeed.com/docs/filters/convert_jpeg_to_webp/): Convert JPEG to WebP
- [`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
- [`convert_jpeg_to_avif`](https://modpagespeed.com/docs/filters/convert_jpeg_to_avif/): Convert JPEG to AVIF
- [`convert_to_avif_animated`](https://modpagespeed.com/docs/filters/convert_to_avif_animated/): Animated AVIF
- [`convert_to_avif_lossless`](https://modpagespeed.com/docs/filters/convert_to_avif_lossless/): Lossless AVIF

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