Generating an animated GIF in Python

后端 未结 3 679
野的像风
野的像风 2020-12-30 06:50

I\'m trying to generate an animated GIF using images2gif.py (pastebin to the most recent verson : bit.ly/XMMn5h ).

I\'m using this Python script:

         


        
3条回答
  •  清酒与你
    2020-12-30 07:15

    In the list constructor

        (fn for fn in os.listdir('.') if fn.endswith('.gif'))
    

    the endswith is case sensitive, so if you happen to have all GIF images, then they won't be found, and you will get a

        ValueError: max() arg is an empty sequence
    

    error.

    I suggest using

        (fn for fn in os.listdir('.') if fn.endswith('.gif') or fn.endswith('.GIF'))
    

    for success with this. Also, it's a good idea to create the animated gif file in the parent (or at least another) directory.

提交回复
热议问题