<?php
/**
* Thanks to ZeBadger for original example, and Davide Gualano for pointing me to it
* Original at http://it.php.net/manual/en/function.imagecreatefromgif.php#59787
*
* Un gif animado contiene multiples "frames", cada "frame" tiene una cabecera
* copuesta por:
* Una secuenda de 4 bytes (\x00\x21\xF9\x04)
* 4 bytes variables
* Una secuenda de 2-bytes (\x00\x2C)
*
* Con esta funcion se lee el archivo entero y buscamos que haya por lo menos
* dos cabeceras de esta trama.
*
* Funcion que devuelve 1 si el gif es animado
* Tiene que recibir el nombre del archivo con su ubicación fisica en el disco
* donde se ejecuta el php.
**/
function is_animated_gif($filename)
{
$raw = file_get_contents( $filename );
$offset = 0;
$frames = 0;
while ($frames < 2)
{
$where1 = strpos($raw, "\x00\x21\xF9\x04", $offset);
if ( $where1 === false )
{
break;
}else{
$offset = $where1 + 1;
$where2 = strpos( $raw, "\x00\x2C", $offset );
if ( $where2 === false )
{
break;
}else{
if ( $where1 + 8 == $where2 )
{
$frames ++;
}
$offset = $where2 + 1;
}
}
}
return $frames > 1;
}
echo "<br>".is_animated_gif("imagen.gif");
?>
Comentarios sobre la versión: Versión 1 (0)
No hay comentarios