Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python resizing animated gif with PIL

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:

enter image description here

How do I solve this problem?

like image 422
hllau Avatar asked Oct 15 '25 03:10

hllau


1 Answers

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:])

like image 117
Manivannan Murugavel Avatar answered Oct 16 '25 17:10

Manivannan Murugavel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!