I have gifone that I would like to change using pillowto reduce its size. The current size gifis 2 MB.
I'm trying to
In JPEG format, the following fragment is usually sufficient, so a large image sharply reduces its size.
from PIL import Image
im = Image.open("my_picture.jpg")
im = im.resize((im.size[0] // 2, im.size[1] // 2), Image.ANTIALIAS)
im.save("out.jpg", optimize=True, quality=85)
With GIF, however, this does not work. The following code snippet even does out.gifmore than the original gif:
im = Image.open("my_gif.gif")
im.seek(im.tell() + 1)
im.save("out.gif", save_all=True, optimize=True, quality=10)
print(os.stat("my_gif.gif").st_size)
print(os.stat("out.gif").st_size)
If I add the next line, then only the first frame of the GIF is saved, and not the entire frame of it.
im = im.resize((im.size[0] // 2, im.size[1] // 2), Image.ANTIALIAS)
I was thinking of calling resize()on im.seek()or im.tell(), but none of these methods returns an Image object, so I cannot call resize()on their output.
, Pillow GIF, ?
[] :
" " , :
BigglesZX script, . , Python 2 script, Python 3 ( , Stack Overflow). 2to3 -w gifextract.py script Python 3.
: frame.resize((frame.size[0] // 2, frame.size[1] // 2), Image.ANTIALIAS)
: img.save("out.gif", save_all=True, optimize=True).
gif , :
:
gif my_gif.gif:

Gif (out.gif) https://i.imgur.com/zDO4cE4.mp4 ( Stack Overflow). Imgur ( mp4). gif , gif 1,5 .