Convert GIF to PNG with Python — Pillow, ImageMagick & Browser
- Python Pillow (PIL): img = Image.open("input.gif"); img.save("output.png")
- ImageMagick: convert input.gif output.png — or convert input.gif[0] for first frame only
- Transparency is preserved automatically by both Pillow and ImageMagick
- For one-off conversions without coding, the browser tool is faster than setting up Pillow
Table of Contents
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 ShippingWhen 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:
- One file, right now: Opening a Python script or terminal takes longer than dragging a file into a browser tab
- No Python environment set up: Installing Pillow requires pip and a working Python environment — not available on every machine
- Non-technical users: The browser tool has no learning curve
- Shared computers or restricted environments: No install permissions needed for a browser tool
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 Pillow | ImageMagick | Browser Tool | |
|---|---|---|---|
| Single file speed | Fast | Fast | Fast |
| Batch (100+ files) | Excellent | Excellent | Good |
| Setup time (first use) | ~5 minutes | ~3 minutes | 0 seconds |
| Automation | Yes (scriptable) | Yes (CLI) | No |
| Transparency | Preserved | Preserved | Preserved |
| Install required | Yes | Yes | No |
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 PNGFrequently 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.

