将图像转换为GIF [英] Convert images to GIF

查看:101
本文介绍了将图像转换为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
    ...

这篇关于将图像转换为GIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆