PHP: imagecreatefromgif - :
I wrote two alternate versions of ZeBadger is_ani() function, for determining if a gif file is animated
Original:
http://us.php.net/manual/en/function.imagecreatefromgif.php#59787
The first alternative version is just as memory intensive as the original, and more CPU intensive, but far simpler:
<?php
function is_ani($filename) {
return (bool)preg_match('#(\x00\x21\xF9\x04.{4}\x00\x2C.*){2,}#s', file_get_contents($filename));
}
?>
The second alternative is about as CPU intensive as the original function, but uses less memory (and may also result in less disk activity)
<?php
function is_ani($filename) {
if(!($fh = @fopen($filename, 'rb')))
return false;
$count = 0;
while(!feof($fh) && $count < 2)
$chunk = fread($fh, 1024 * 100);
$count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00\x2C#s', $chunk, $matches);
fclose($fh);
return $count > 1;
}
?>