Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception using "seek" on GIF that contains frames with different modes #6571

Closed
seidnerj opened this issue Sep 12, 2022 · 7 comments · Fixed by #6576
Closed

Exception using "seek" on GIF that contains frames with different modes #6571

seidnerj opened this issue Sep 12, 2022 · 7 comments · Fixed by #6576
Labels

Comments

@seidnerj
Copy link

seidnerj commented Sep 12, 2022

I have an animated GIF that has about 60 frames, some of the frames are encoded in 'L' mode and others are in 'RGB' mode. Many actions, including a simple "seek" command" fail with a "ValueError: images do not match" exception when self.im.paste(frame_im, self.dispose_extent) is issued in GifImagePlugin.py. This happens when "self.im" and "frame_im" have different modes.

This might be a protection technique for not being able to process such files with Pillow.

@seidnerj
Copy link
Author

seidnerj commented Sep 12, 2022

I implemented a small hardcoded fix, though am not sure its the best way to solve this issue, it works for me.

I added the following code (in Pillow 9.2.0):

        if self.im.mode != frame_im.mode:
            if self.im.bands > frame_im.bands:
                frame_im = frame_im.convert(self.im.mode)
            else:
                self.im = self.im.convert(frame_im.mode)

Immediately before the following block in "GifImagePlugin.py":

        if frame_im.mode == "RGBA":
            self.im.paste(frame_im, self.dispose_extent, frame_im)
        else:
            self.im.paste(frame_im, self.dispose_extent)

Either way, the current behavior seems like a bug, even though this might not adhere to animated GIF's spec, it's probably worth a fix.

@radarhere radarhere added the GIF label Sep 12, 2022
@radarhere
Copy link
Member

Could you upload a copy of the image, and simple code that triggers the error?

@radarhere radarhere changed the title Exception when issuing "seek" on an animated gif that contains frames with different modes Exception using "seek" on GIF that contains frames with different modes Sep 13, 2022
@seidnerj
Copy link
Author

seidnerj commented Sep 13, 2022

Here you go, use the code below and the attached GIF.

def main():
    image = Image.open('example.gif')
    image.seek(6)

if __name__ == '__main__':
    main()

example

@radarhere
Copy link
Member

I've created PR #6576 to resolve this.

@seidnerj
Copy link
Author

Great, thanks. I’ll patch my local version accordingly. What release do you expect this to be included in?

@nulano
Copy link
Contributor

nulano commented Sep 13, 2022

Pillow 9.3.0 was due for release on 2022-10-15, but will be delayed a few days due to the delay with the Python 3.11 release. The current estimate is 2022-10-25, you can watch #6460 for updates.

@seidnerj
Copy link
Author

Great. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants