-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
First frame of transparent GIF is read incorrectly #6590
Copy link
Copy link
Closed
Labels
Description
What did you do?
I have a four-frame transparent GIF I want to do some manipulation with (i.e. comparing frames, cropping).

I ran this code to turn each frame into an array, and saved each array as a png for visualization purposes.
from PIL import Image
import numpy
inputFileName = "squidcat.gif"
outputFileName = "pngcat"
frames = []
with Image.open(inputFileName, formats=["GIF"]) as imageObject:
# save each frame to a numpy array
for frame_num in range(0, imageObject.n_frames):
imageObject.seek(frame_num)
frames.append(numpy.array(imageObject))
# do something with the numpy frames
for i in range(len(frames)):
# save each frame as a png to visualize
fileName = outputFileName + "_" + str(i) + ".png"
Image.fromarray(frames[i]).save(fileName)What did you expect to happen?
I expected the program to generate four png files containing the four transparent frames.
What actually happened?
The first frame was completely black, with the subsequent three turning out normally. I've included my results below:




What are your OS, Python and Pillow versions?
- OS: Mac OS 12.5.1 (21G83)
- Python: 3.10.6
- Pillow: 9.2.0
Reactions are currently unavailable