I follow the step at Resize GIF animation, pil/imagemagick, python to resize image using PIL
and image2gif
. However, I got the resized gif washed out like below:
How do I solve this problem?
I follow the step at Resize GIF animation, pil/imagemagick, python to resize image using PIL
and image2gif
. However, I got the resized gif washed out like below:
How do I solve this problem?
Here is my code
from PIL import Image, ImageSequence
filename = "demo.gif"
new_width = 100
new_height = 100
with Image.open(filename) as im:
frames = []
for frame in ImageSequence.Iterator(im):
frame = frame.resize((new_width, new_height))
frames.append(frame)
print(f"length of freames {len(frames)}")
frames[0].save('resized_image.gif', save_all=True, append_images=frames[1:])
I have not tried this, but this suggests that the way to maintain transparency in GIF images with PIL when saving is:
im = Image.open(...)
transparency = im.info["transparency"]
...
out.save("out.gif", transparency=transparency)
Update pillow to version 9.1.0.