将图像转换为GIF
我正在尝试将一系列JPG文件转换为单个动画GIF.我使用Python脚本images2gif.py( https://pypi.python.org /pypi/images2gif/1.0.1 )效果很好,但我不知道如何使GIF仅在图像中运行1次.我可以将loops设置为1,使其运行2次(即1次循环)或0-导致其无限运行.有建议吗?
I am attempting to convert a series of JPG files to a single animated GIF. I have done this using the Python script images2gif.py (https://pypi.python.org/pypi/images2gif/1.0.1) It works really well, but I don't know how to make the GIF only run through the images 1 time. I can set the loops=1, which run through it 2 times (i.e. 1 loop) or 0 - which causes it to run infinitly. An suggestions?
只注意到@Jongware在评论中击败了我.
Only just noticed that @Jongware beat me to it in comments.
源显示以下内容:
if loops==0 or loops==float('inf'):
loops = 2**16-1
#bb = "" # application extension should not be used
# (the extension interprets zero loops
# to mean an infinite number of loops)
# Mmm, does not seem to work
if True:
bb = "\x21\xFF\x0B" # application extension
bb += "NETSCAPE2.0"
bb += "\x03\x01"
bb += intToBin(loops)
bb += '\x00' # end
return bb
如您所见,始终会添加应用程序扩展名.从扩展名规范
As you can see, the application extension is always added. From a spec for the extension
字节17到18:0到65535,是低字节字节格式的无符号整数.这表明应该执行循环的迭代次数.
bytes 17 to 18 : 0 to 65535, an unsigned integer in lo-hi byte format. This indicate the number of iterations the loop should be executed.
简而言之,任何值都会多次播放.看来避免这种情况的方法是忽略扩展本身.
In short, any value will play through a multiple times. It seems the way to avoid this is to omit the extension itself.
if loops != 1:
bb = "\x21\xFF\x0B" # application extension
...