laggykiller / rlottie-python

A ctypes API for rlottie, with additional functions for getting Pillow Image.
https://rlottie-python.readthedocs.io/en/latest/
GNU Lesser General Public License v2.1
15 stars 1 forks source link

Bad GIF quality #1

Closed star-39 closed 1 year ago

star-39 commented 1 year ago

Hi, the converted GIF has very strong color banding.

image

It looks even uglier when it moves.

AnimatedEmojies_🥳

laggykiller commented 1 year ago

This issue is not quite related to this library...

However, I did found this issue: https://github.com/python-pillow/Pillow/issues/4941

Hope this helps! If not, please share the tgs so I can take a look.

star-39 commented 1 year ago

Oh, you seems right!

But my thought is to make this library produce better quality GIFs, so it's somehow related? Please allow me to edit the issue descriptions.

Anyway, thanks for your attention! If you think current procedure is fine, then... it's fine! Not a big problem after all.

laggykiller commented 1 year ago

I see, but if I want the library to produce high quality GIF with Image.LIBIMAGEQUANT, then I have to somehow include custom compiled Pillow with support for libimagequant as dependency in this project, which I think is a feature creep. I think this job should be left to users, as there is many ways to quantize a image (e.g. number of colors, method), each with pros and cons (e.g. File size, image quality), and there is no single best method. Users should decide how their image be quantized based on their use case.

If users want to create gif with Image.LIBIMAGEQUANT, they can just easily (?):

from rlottie_python import LottieAnimation
from PIL import Image

anim = LottieAnimation.from_file('example/sample.json')
totalframe = anim.lottie_animation_get_totalframe()
frame_duration = 1000 / anim.lottie_animation_get_framerate()

im_list = []
for frame in range(totalframe):
    im = anim.render_pillow_frame(frame_num=frame)
    im = im.quantize(255, method=Image.LIBIMAGEQUANT)
    im_list.append(im)

im_list[0].save('animation.gif', save_all=True, append_images=im_list[1:], duration=int(frame_duration))
star-39 commented 1 year ago

Not exactly that you must use Image.LIBIMAGEQUANT to improve quality.... I just happen to found that it did.

Well, if you think current save_animation result is okay, then it's okay! Thank you.