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

Read and write some gifs wrong, with "artifacts". "optimize" doesn't work #2543

Closed
pl7ofit opened this issue May 26, 2017 · 5 comments · Fixed by #5857
Closed

Read and write some gifs wrong, with "artifacts". "optimize" doesn't work #2543

pl7ofit opened this issue May 26, 2017 · 5 comments · Fixed by #5857
Labels
Bug Any unexpected behavior, until confirmed feature. GIF
Projects

Comments

@pl7ofit
Copy link

pl7ofit commented May 26, 2017

What did you do?

I read each frame of the gif, and then write them to a file.

What did you expect to happen?

That everything will work without a headache =)

What actually happened?

Some gif files wrote with artifacts and "optimize" doesn't work
pic2.gif
Gif №2

pic6.gif
Gif №6

I think compare successful and unsuccessful gifs will be right. Therefore I downloaded the gifs archive
"Bad" and "good" gifs tar archive

What versions of Pillow and Python are you using?

Pillow-4.1.1-cp35-cp35m-manylinux1_x86_64.whl
Python 3.5.2
Ubuntu 16.04.2 amd64

from PIL import Image, ImageChops, ImageSequence

f = Image.open('file.gif')
frames = []
framesIterator = ImageSequence.Iterator(f)
for frame in [ frame.copy() for frame in framesIterator ]: frames.append(frame)
frame.save('out.gif', save_all=True, optimize=True, append_images=frames)
@pl7ofit pl7ofit changed the title Pillow gif plugin read and write some gifs wrong, with "artifacts". "optimize" doesn't work. GIF plugin read and write some gifs wrong, with "artifacts". "optimize" doesn't work. May 26, 2017
@wiredfool
Copy link
Member

There's definitely something odd with these images in the palette or dispose options, as imagemagick isn't displaying them properly either. Different, but not proper.

Also, as an aside, optimize trims the palette size if there are unused items and the palette can be reduced to the next lower power of 2. There's a max of ~760 bytes per palette that could be saved (if there's a pathologically bad encoding of a b/w image). It's not going to do much of anything for these images.

@radarhere radarhere added the GIF label May 27, 2017
@petrasovaa
Copy link

I have very similar problem (probably the same), it degrades the quality of the images, it adds noise. See for example:
https://trac.osgeo.org/grass/raw-attachment/ticket/3367/noisy.gif

@wiredfool
Copy link
Member

wiredfool commented Sep 12, 2017

The noise is likely dither, which is used to make palette images more perceptually correct in color at the expense of noise. Pillow's quantize doesn't have a very sophisticated method of determining if dither is needed, it's either on or off depending on the parameter passed in to Image.quantize.

edit -- that's Image.convert, not Image.quantize.

@petrasovaa
Copy link

Thanks for responding, that's what I needed, thank you!

@radarhere radarhere changed the title GIF plugin read and write some gifs wrong, with "artifacts". "optimize" doesn't work. GIF plugin read and write some gifs wrong, with "artifacts". "optimize" doesn't work Sep 22, 2017
@radarhere radarhere changed the title GIF plugin read and write some gifs wrong, with "artifacts". "optimize" doesn't work Read and write some gifs wrong, with "artifacts". "optimize" doesn't work Mar 23, 2019
@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life added the Bug Any unexpected behavior, until confirmed feature. label May 11, 2019
@aclark4life aclark4life moved this from Backlog to In progress in Pillow May 11, 2019
@radarhere
Copy link
Member

I've created PR #5857 to fix the original problem here, resolving this.

Pillow automation moved this from In progress to Closed Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature. GIF
Projects
Pillow
  
Closed
Development

Successfully merging a pull request may close this issue.

5 participants