pythonpython-imaging-librarygifimage-conversion

How to convert PNGs to GIF with very short delay in Python?


The only similar thread I found on this is Gif Frame Duration Seems Slower Than Expected which somewhat captured my problem, but the 'solution' doesn't work.

My problem is that I am using Pillow to convert PNGs to GIF with the following code:

frames = [Image.open("_bg0.png"), Image.open("_bg1.png"), Image.open("_bg2.png"), Image.open("_bg3.png")]

frames[0].save('_test.gif', format='GIF',
               append_images=frames[1:],
               save_all=True,
               disposal = 2,
               duration=4, loop=0, transparency=0)

I want the duration to be 4ms, however the output looks much slower than this. Here is an example (top is Pillow, bottom is EzGif, same delay specified).

Using Pillow

Using EzGif

I saw it has something to do with the frame rate, however everything I tried in the linked thread didn't work (particularly setting a value slightly above 1). I've tried setting it to 0, 1, 2, 3, 4 and many values in between.

How do I fix this? I want to be able to do this conversion in Python.


Solution

  • As mentioned in the comments, I set mine to 20 ms (I had tried 2/100 ms rather than 2/100 s which caused the issue described earlier).

    This has fixed the problem, and indeed there was already a 'speed cap' when using EzGif I just didn't realise.