Skip to content

Commit

Permalink
Fix performance regression from last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
iherwig committed Jun 14, 2024
1 parent f7904dc commit 9c4f2e5
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/wcmf/lib/io/ImageUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,24 @@ private static function resizeImage($sourceFile, $destFile, $width, $type=null,
* @return boolean
*/
private static function isAnimated($imageFile) {
if (!FileUtil::fileExists($imageFile)) {
if (!($fh = @fopen($imageFile, 'rb'))) {
return false;
}
$manager = self::getImageManager();
return $manager->read($imageFile)->isAnimated();
$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
while (!feof($fh) && $count < 2) {
$chunk = 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;
}

/**
Expand Down

0 comments on commit 9c4f2e5

Please sign in to comment.