Skip to content

Commit 9c4f2e5

Browse files
committed
Fix performance regression from last commit
1 parent f7904dc commit 9c4f2e5

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/wcmf/lib/io/ImageUtil.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,24 @@ private static function resizeImage($sourceFile, $destFile, $width, $type=null,
396396
* @return boolean
397397
*/
398398
private static function isAnimated($imageFile) {
399-
if (!FileUtil::fileExists($imageFile)) {
399+
if (!($fh = @fopen($imageFile, 'rb'))) {
400400
return false;
401401
}
402-
$manager = self::getImageManager();
403-
return $manager->read($imageFile)->isAnimated();
402+
$count = 0;
403+
// An animated gif contains multiple "frames", with each frame having a header made up of:
404+
// * a static 4-byte sequence (\x00\x21\xF9\x04)
405+
// * 4 variable bytes
406+
// * a static 2-byte sequence (\x00\x2C) (some variants may use \x00\x21 ?)
407+
408+
// We read through the file til we reach the end of the file, or we've found
409+
// at least 2 frame headers
410+
while (!feof($fh) && $count < 2) {
411+
$chunk = fread($fh, 1024 * 100); //read 100kb at a time
412+
$count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $chunk, $matches);
413+
}
414+
415+
fclose($fh);
416+
return $count > 1;
404417
}
405418

406419
/**

0 commit comments

Comments
 (0)