Skip to content

Improperly saving gif frame with some gif images #5734

@mrnextdoor0000

Description

@mrnextdoor0000
from PIL import Image, ImageSequence

def getframe(src, out):
    with Image.open(src) as img:
        print(f'file opened')
        i = 0
        for frame in ImageSequence.Iterator(img):
            if i == 1:
                frame.save(out)
                break
            else:
                i += 1

i used this method to get a 2nd frame of a gif image.
i got the frame but it was not good.
source gif:
test7

result 2nd frame i got (gif format):
result7

i tried to get 1st frame and 1st frame was very good unlike the 2nd.

i also tried another gif image has transparency.
i added convert function before save the frame

frame = frame.convert('RGB')

source gif:
test8

result 2nd frame i got (jpg format):
result8

i think the second case was occured since i did not set the background color. But there is no options about background of jpeg with Image.save().

There is some bug.. or something i missed.
Please let me know, thank you.

i used python 3.9.7 and pillow 8.3.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions