I have PNG (as well as JPEG) images uploaded to my site.
They should be static (i.e. one frame).
There is such thing as APNG.
I'd like to suggest a more optimised version, which doesn't read the whole file, as those could be quite big, and still rely on the acTL before IDAT rule:
function identify_apng($filepath) {
$apng = false;
$fh = fopen($filepath, 'r');
$previousdata = '';
while (!feof($fh)) {
$data = fread($fh, 1024);
if (strpos($data, 'acTL') !== false) {
$apng = true;
break;
} elseif (strpos($previousdata.$data, 'acTL') !== false) {
$apng = true;
break;
} elseif (strpos($data, 'IDAT') !== false) {
break;
} elseif (strpos($previousdata.$data, 'IDAT') !== false) {
break;
}
$previousdata = $data;
}
fclose($fh);
return $apng;
}
Speed is enhanced from 5x to 10x or more depending on how big the file is, and it also uses a lot less memory.
NB: this maybe could be tweaked more with the size given to fread or with the concatenation of the previous chunk with the current one. By the way, we need this concatenation as the acTL/IDAT word might be split between two read chunks.