Resize_to (optional): new size of the gif. If not set, the original gif will be overwritten. Save_as (optional): Path of the resized gif. Only the first frame was displayed (you can see it here).įull code (should the above gist be deleted): def resize_gif(path, save_as=None, resize_to=None): Likewise, while imgur seems to make up for the speed problem, the GIF wouldn't display correctly when I tried to upload it to stack.imgur.While the GIF displays just fine when hosted by imgur, there is a speed issue when I open it from my computer where the entire GIF only take 1.5 seconds.The is not perfect so feel free to fork and improve it. It is using the thumbnail method of Pillow rather than the resize method as I found the resize method did not work. Using BigglesZX's script, I have created a new script which resizes a GIF using Pillow. When I open the gif file from my computer, the entire gif lasts about 1.5 seconds. Imgur made it slower (and converted it to mp4). Gif after processing ( out.gif) (I could not add it to Stack Overflow ). The gif speed is increased and the gif does not loop. I am not sure that the resize method works, as out.gif is still 7.5MB. The new gif is now saved and works, but there is 2 main problems : I've been saving all the frames together: img.save("out.gif", save_all=True, optimize=True). I have been resicing each frame individually: frame.resize((frame.size // 2, frame.size // 2), Image.ANTIALIAS) Running 2to3 -w gifextract.py makes that script compatible with Python 3. It is useful to note that this is a Python 2 script, and my project is written in Python 3 (I did mention that detail initially, but it was edited out by the Stack Overflow Community). I am using BigglesZX's script to extract all frames. Would you know how I can use Pillow to decrease the size of my GIF while keeping all of its frames?įollowing Old Bear's response, I have done the following changes: I've been thinking about calling resize() on im.seek() or im.tell() but neither of these methods return an Image object, and therefore I cannot call resize() on their output. im = im.resize((im.size // 2, im.size // 2), Image.ANTIALIAS) # should decrease its size If I add the following line, then only the first frame of the GIF is saved, instead of all of its frame. Im.save("out.gif", save_all=True, optimize=True, quality=10) # should decrease its quality Im.seek(im.tell() + 1) # loads all frames The following piece of code even makes the out.gif bigger than the initial gif: im = Image.open("my_gif.gif") With a GIF, though, it does not seem to work. Im.save("out.jpg", optimize=True, quality=85) # decreases its quality Im = im.resize((im.size // 2, im.size // 2), Image.ANTIALIAS) # decreases width and height of the image With JPEG, the following piece of code is usually enough so that large image drastically decrease in size. Resize it so its height / width is smaller I have a gif that I would like to resize with pillow so that its size decreases.
0 Comments
Leave a Reply. |