Blog
Wild & Free Tools

Convert GIF to PNG with Python — Pillow, ImageMagick & Browser

Last updated: March 2026 7 min read
Quick Answer

Table of Contents

  1. Python Pillow method
  2. Transparency with Pillow
  3. ImageMagick method
  4. When to use browser tool instead
  5. Performance comparison
  6. FAQs
  7. Frequently Asked Questions

If you are already working in Python or need to automate GIF-to-PNG conversion at scale, Pillow is the standard library. If you want a scriptable command-line approach, ImageMagick is the tool. And if you need a single file converted without writing any code, a browser tool is faster than either. This guide covers all three.

Convert GIF to PNG with Python Pillow

Pillow (the maintained fork of PIL) is the standard Python image library. Install it with pip:

pip install Pillow

Single file conversion:

from PIL import Image

img = Image.open("input.gif")
img.save("output.png")
print("Converted successfully")

For animated GIFs, Pillow opens the first frame by default. The output PNG will be the first frame with transparency preserved.

Explicit frame selection:

from PIL import Image

img = Image.open("input.gif")
img.seek(0)  # Frame 0 = first frame; change to 1, 2, etc. for other frames
img.save("output.png")

Batch conversion — all GIFs in a folder:

import os
from PIL import Image

input_dir = "gifs/"
output_dir = "pngs/"
os.makedirs(output_dir, exist_ok=True)

for filename in os.listdir(input_dir):
    if filename.lower().endswith(".gif"):
        gif_path = os.path.join(input_dir, filename)
        png_path = os.path.join(output_dir, filename[:-4] + ".png")
        with Image.open(gif_path) as img:
            img.save(png_path)
            print(f"Converted: {filename}")

print("Done.")

Handling Transparency in Pillow

GIF transparency is automatically preserved by Pillow when saving to PNG. No extra code is needed for transparent GIFs:

from PIL import Image

img = Image.open("transparent.gif")
img.save("transparent.png")
# Transparency is preserved automatically

If you need to convert the GIF to RGBA mode first (useful for some image manipulation workflows):

from PIL import Image

img = Image.open("input.gif").convert("RGBA")
img.save("output.png")

The convert("RGBA") call ensures the output PNG has a proper alpha channel, which is useful if you plan to manipulate the image further before saving.

Convert GIF to PNG with ImageMagick

ImageMagick is a command-line tool available on Linux, Mac, and Windows. Install via your package manager (see the Linux post for install commands).

Single file:

convert input.gif output.png

First frame only (for animated GIFs):

convert "input.gif[0]" output.png

All frames to individual PNGs:

convert input.gif output_%03d.png

This produces output_000.png, output_001.png, etc. — one per frame.

Batch conversion in bash:

for f in *.gif; do convert "${f}" "${f%.gif}.png"; done

ImageMagick preserves transparency automatically when converting to PNG.

Sell Custom Apparel — We Handle Printing & Free Shipping

When the Browser Tool Is Better Than Python

Python and ImageMagick are the right tools for automated, repeatable workflows. For these situations, a browser tool is faster:

Robin GIF to PNG is the browser option — processes files locally with no upload, handles batch conversion, and requires no setup.

Performance: Python vs ImageMagick vs Browser Tool

Python PillowImageMagickBrowser Tool
Single file speedFastFastFast
Batch (100+ files)ExcellentExcellentGood
Setup time (first use)~5 minutes~3 minutes0 seconds
AutomationYes (scriptable)Yes (CLI)No
TransparencyPreservedPreservedPreserved
Install requiredYesYesNo

Python FAQs

Try It Free — No Signup Required

Runs 100% in your browser. No data is collected, stored, or sent anywhere.

Open Robin GIF to PNG

Frequently Asked Questions

Does Python Pillow preserve transparency when converting GIF to PNG?

Yes. Pillow preserves GIF transparency automatically when saving to PNG. No extra code is needed. If you need explicit RGBA mode, use img.convert("RGBA") before saving.

How do I convert all frames of an animated GIF to PNG with Python?

Use img.seek(frame_number) to select each frame, then save: for frame in range(img.n_frames): img.seek(frame); img.save(f"frame_{frame:03d}.png"). The n_frames attribute gives the total frame count.

Why does Pillow show an error when opening some GIF files?

Common causes: the file is corrupt, it has a non-standard GIF extension, or it is a GIF with unusual encoding. Try converting with ImageMagick as a fallback. Large animated GIFs may also need special handling — use img.seek(0) to explicitly select the first frame.

Can I use wand (Python bindings for ImageMagick) instead of Pillow?

Yes. pip install wand gives you Python bindings for ImageMagick. The API is slightly different: from wand.image import Image; with Image(filename="input.gif") as img: img.save(filename="output.png"). Both produce correct results.

Andrew Walsh
Andrew Walsh Developer Tools & API Writer

Andrew worked as a developer advocate at two SaaS startups writing API documentation used by thousands of engineers.

More articles by Andrew →
Launch Your Own Clothing Brand — No Inventory, No Risk