Reading animated GIF in PHP

不打扰是莪最后的温柔 提交于 2019-12-08 06:35:45

问题


I am in need of reading the individual frames of an animated GIF in PHP.

I use GD all the time for image manipulation, but unfortunately it lacks the capability to handle multiple frames in a GIF image.

I'm currently in the middle of carving up the GIF file format in an attempt to make my own extractor, but before I go any further I was wondering if anyone had any pointers for code that already does this - I can't be the first to want to handle animations in PHP, surely.


回答1:


Yup. I think the ImageMagick extension should work nicely in your case. I've used it in my PHP codes before, and while I've not used GD before, ImageMagick has been sufficient for my minor image manipulation needs. =)

$agif = new Imagick("animated.gif");

// Loop over all individual frames 
foreach ($agif as $frame) {

    // Do whatever you need to do here 

}

// Save the modified gif
$agif->writeImages("new_animated.gif", true);

The full set of functions available through the ImageMagick PHP extension can be found at http://php.net/manual/en/book.imagick.php



来源:https://stackoverflow.com/questions/9356583/reading-animated-gif-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!