Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/Resizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ protected function processResize(ImageInterface $image, ResizeConfiguration $con
return $this->createImage($image, $image->getPath());
}

if ($this->isAnimatedGif($image->getPath())) {
return $this->createImage($image, $image->getPath());
}

$cachePath = Path::join($this->cacheDir, $this->createCachePath($image->getPath(), $coordinates, $options, false));

if (!$options->getBypassCache()) {
Expand Down Expand Up @@ -365,4 +369,30 @@ private function encodeBase32(string $bytes): string

return implode('', $result);
}

/**
* Check if a file is an animated GIF.
*/
private function isAnimatedGif(string $path): bool
{
if (strtolower(pathinfo($path, PATHINFO_EXTENSION)) !== 'gif') {
return false;
}

if (!file_exists($path)) {
return false;
}

$content = file_get_contents($path, false, null, 0, 3145728);

if ($content === false) {
return false;
}

// Count occurrences of the GIF image separator byte
// Animated GIFs have multiple image blocks (0x00,0x21,0xF9)
$count = preg_match_all('#\x00\x21\xF9\x04#', $content, $matches);

return $count > 1;
}
}