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.
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