动画 gif
If you tweet an animated GIF, you'll notice that Twitter takes it and converts it to an mp4. I'd speculate that they do that conversion because an MP4 is better supported across platforms, at least in that they allow for playing/pause of the animation. And with a video you can prevent infinite looping, unlike a GIF. How can you determine if a GIF is animated though? I found a few good solutions.
如果您发布动画GIF推文,您会注意到Twitter接受了它并将其转换为mp4。 我推测他们会进行这种转换,因为跨平台更好地支持MP4,至少因为它们允许播放/暂停动画。 与视频不同,与GIF不同,您可以防止无限循环。 您如何确定GIF是否为动画呢? 我找到了一些好的解决方案。
带有ImageMagick的命令行 (Command Line with ImageMagick)
ImageMagick, the amazing image manipulation library, provides a method for counting frames in a GIF:
令人惊叹的图像处理库ImageMagick提供了一种用于计算GIF中的帧的方法:
./ImageMagick-6.9.0/bin/identify -format %n wtf.gif
The command above will provide you a count of the frames within the GIF.
上面的命令将为您提供GIF中帧的计数。
动画gif检测器 (animated-gif-detector)
For those of you that prefer JavaScript (...my people...), I found a really simple animated GIF detection library on NPM: animated-gif-detector. Its API couldn't be shorter:
对于那些喜欢JavaScript的人(...我的人们...),我在NPM上找到了一个非常简单的GIF动画检测库: animated-gif-detector 。 其API不能再短一些:
var fs = require('fs');
var animated = require('animated-gif-detector');
> animated(fs.readFileSync('wtf.gif'));
// true
> animated(fs.readFileSync('blank.gif'));
// false
The function call simply returns true
or false
, representing if the GIF is animated. Exactly what I wanted!
该函数调用仅返回true
或false
,表示GIF是动画的。 正是我想要的!
As for what each library looks for, I've seen some ugly bit code I wont try to describe. If you want to determine if a GIF is animated, however, it's as easy as the utilities above!
至于每个库的查找内容,我已经看到了一些我不想尝试描述的难看的代码。 但是,如果要确定GIF是否具有动画效果,则它就像上面的实用程序一样简单!
动画 gif