Skip to content

Commit

Permalink
Update Gif info class.
Browse files Browse the repository at this point in the history
  • Loading branch information
ve3 committed Apr 3, 2024
1 parent 3f66356 commit c319a70
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Rundiz/Image/Extensions/Gif.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,21 @@ public function gifInfo($file)
$header = unpack($header_format, $data);
unset($data, $header_format);

rewind($fp);
// check is animated gif.
// known problem: this couldn't detected all animated GIF files.
// https://stackoverflow.com/a/415942/128761 Original source code.
$count = 0;
$chunk = false;
while(!feof($fp) && $count < 2) {
$chunk = fread($fp, 1024 * 100); //read 100kb at a time
$count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00[\x2C\x21]#s', $chunk, $matches);
$chunk = ($chunk ? substr($chunk, -20) : "") . fread($fp, 1024 * 100); //read 100kb at a time
// \x21 = An Extension Block
// xF9 = Graphic Control Extension for frame #1
// \x04 = Number of bytes (4) in the current sub-block
// .{4} = any 4 byte
// \x2C = An Image Descriptor
// \x21 = An Extension Block
$count += preg_match_all('#\x00?\x21\xF9\x04.{4}\x00[\x2C\x21]#s', $chunk, $matches);
}// endwhile;
// end check animated gif.

Expand Down

0 comments on commit c319a70

Please sign in to comment.