note 59787 added to function.imagecreatefromgif
| From: | ZeBadger at osu1 dot php dot net | Date: | Thu, 15 Dec 2005 17:15:57 +0000 |
| Subject: | note 59787 added to function.imagecreatefromgif | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100218@lists.php.net to get a copy of this message | ||
I have written this code to detect if a gif file is animated or not. I thought I would share it :-)
<?php
function is_ani($filename)
{
$filecontents=file_get_contents($filename);
$str_loc=0;
$count=0;
while ($count < 2) # There is no point in continuing after we find a 2nd frame
{
$where1=strpos($filecontents,"\x00\x21\xF9\x04",$str_loc);
if ($where1 === FALSE)
{
break;
}
else
{
$str_loc=$where1+1;
$where2=strpos($filecontents,"\x00\x2C",$str_loc);
if ($where2 === FALSE)
{
break;
}
else
{
if ($where1+8 == $where2)
{
$count++;
}
$str_loc=$where2+1;
}
}
}
if ($count > 1)
{
return(true);
}
else
{
return(false);
}
}
exec("ls *gif" ,$allfiles);
foreach ($allfiles as $thisfile)
{
if (is_ani($thisfile))
{
echo "$thisfile is animated<BR>\n";
}
else
{
echo "$thisfile is NOT animated<BR>\n";
}
}
?>
It could quite easily be modified to count the number of frames if you required.
----
Manual Page -- http://www.php.net/manual/en/function.imagecreatefromgif.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59787
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59787&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59787&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59787&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59787&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59787&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59787&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59787&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59787&report=yes
Search -- http://master.php.net/manage/user-notes.php