1

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.

2
  • Have you checked out ImageMagick? I haven't ever used it in PHP, but it looks like it might be able to do what you're looking for. Check out example #5 on this page. Commented Feb 20, 2012 at 5:34
  • It'd be nice if half of PHP.net weren't down, most importantly static.php.net and pecl.php.net... Commented Feb 20, 2012 at 6:06

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

I'm running PHP on Windows and I can't work out how to get imagick added. I know SO isn't really for this kind of question, but would you have any idea how to get it working on Windows?
You'll need the windows installer from here <imagemagick.org/script/binary-releases.php#windows> to install on your system first, but the usual installation of PHP extensions don't apply to Windows so I'm afraid I can't share much experience there. This question on SO might help though. <stackoverflow.com/questions/3036847/…> =) Cheers!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.