动画 gif_检测GIF是否为动画

动画 gif

WTF

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!

该函数调用仅返回truefalse ,表示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是否具有动画效果,则它就像上面的实用程序一样简单!

翻译自: https://davidwalsh.name/detect-gif-animated

动画 gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值