이것은 현재 최고 득표 답변의 개선이지만 아직 논평 할만한 평판이 충분하지 않습니다. 그 대답의 문제점은 파일을 100KB 청크로 읽고 프레임 마커의 끝 부분을 2 청크로 분할 할 수 있다는 것입니다. 이를 해결하려면 이전 프레임의 마지막 20b를 다음 프레임에 추가하십시오.
<?php
function is_ani($filename) {
if(!($fh = @fopen($filename, 'rb')))
return false;
$count = 0;
//an animated gif contains multiple "frames", with each frame having a
//header made up of:
// * a static 4-byte sequence (\x00\x21\xF9\x04)
// * 4 variable bytes
// * a static 2-byte sequence (\x00\x2C) (some variants may use \x00\x21 ?)
// We read through the file til we reach the end of the file, or we've found
// at least 2 frame headers
$chunk = false;
while(!feof($fh) && $count < 2) {
//add the last 20 characters from the previous string, to make sure the searched pattern is not split.
$chunk = ($chunk ? substr($chunk, -20) : "") . fread($fh, 1024 * 100); //read 100kb at a time
$count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches);
}
fclose($fh);
return $count > 1;
}
저자는 ImageMagick이 없다고 말했습니다. 하지만 모든 사람들이 gif가 애니메이션처럼 생겨서 Google 같은 곳에서 나처럼 발견되면 어떤 방법 으로든 검색 할 수 있습니다. ImageMagick은 매우 쉽게이 작업을 수행합니다. http://php.net/manual/en/imagick.getimageiterations .php – Lukas