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

Image distortion in GIFs when I use crop #5661

Closed
shangcheng77 opened this issue Aug 9, 2021 · 7 comments
Closed

Image distortion in GIFs when I use crop #5661

shangcheng77 opened this issue Aug 9, 2021 · 7 comments
Labels

Comments

@shangcheng77
Copy link

shangcheng77 commented Aug 9, 2021

img = pil_img.open(img_path)
width, height = img.size
del_width = random.randint(1, 10)
del_height = random.randint(1, 10)
box = (0, 0, width - del_width, height - del_height)
frames = [img.crop(box) for frame in range(0, img.n_frames) if not img.seek(frame)]
frames[0].save(new_path, save_all=True, append_images=frames, loop=0, duration=img.info['duration'])

fbdpow

@radarhere radarhere added the GIF label Aug 9, 2021
@shangcheng77
Copy link
Author

The gif after deal is bigger than 10M,so I can’t upload it

@radarhere
Copy link
Member

I'm able to upload it. Is this what you're seeing? So you're talking about the occasional frame having incorrect colours?

out

@shangcheng77
Copy link
Author

shangcheng77 commented Aug 9, 2021

img = pil_img.open(img_path)
width, height = img.size
box = (0, 0, width - 10, height - 10)
frames = [img.crop(box) for frame in range(0, img.n_frames) if not img.seek(frame)]
frames[0].save(new_path, save_all=True, append_images=frames[:60], loop=0, duration=img.info['duration'])

fbdpow

new

I saved less frames to limit gif size,my results of crop is serious distortion

@radarhere
Copy link
Member

What version of Pillow are you using? If I go back to Pillow 8.1.2, then I get your version. So I expect if you upgrade to a more recent version of Pillow, your output will be improved to match mine.

@radarhere
Copy link
Member

To confirm that you are using the upgraded Pillow, does print(pil_img.__version__) show 8.3.1?

@shangcheng77
Copy link
Author

8.3.1 In another gif
dtax03

new

@radarhere radarhere changed the title Image distortion when I using crop to deal some gifs Image distortion in GIFs when I use crop Nov 9, 2021
@radarhere
Copy link
Member

Pillow 9.0.0 has significantly improved reading animated GIFs thanks to #5857.

If this issue is still a problem when using Pillow 9.0.0, please let us know.

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

No branches or pull requests

2 participants