From 1fc6810ae0a05ad1c7be6b327450c3c327bbba17 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 11 Jul 2024 13:55:23 +1200 Subject: [PATCH] ENH Remove animation for thumbnails by default. --- code/Model/ThumbnailGenerator.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/code/Model/ThumbnailGenerator.php b/code/Model/ThumbnailGenerator.php index 29dc6b2e9..47d244adf 100644 --- a/code/Model/ThumbnailGenerator.php +++ b/code/Model/ThumbnailGenerator.php @@ -7,6 +7,7 @@ use SilverStripe\Assets\Storage\AssetContainer; use SilverStripe\Assets\Storage\AssetStore; use SilverStripe\Assets\Storage\DBFile; +use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Config\Configurable; /** @@ -65,6 +66,8 @@ class ThumbnailGenerator */ private static $method = 'FitMax'; + private bool $allowsAnimation = false; + /** * Generate thumbnail and return the "src" property for this thumbnail * @@ -107,6 +110,14 @@ public function generateThumbnail(AssetContainer $file, $width, $height) $file = $file->existingOnly(); } + // Try to remove the animation if we can + if (!$this->getAllowsAnimation() && $file->getIsAnimated() && ClassInfo::hasMethod($file, 'RemoveAnimation')) { + $noAnimation = $file->RemoveAnimation(); + if ($noAnimation) { + $file = $noAnimation; + } + } + // Make large thumbnail $method = $this->config()->get('method'); return $file->$method($width, $height); @@ -173,4 +184,15 @@ public function setGenerates($generates) $this->generates = $generates; return $this; } + + public function getAllowsAnimation(): bool + { + return $this->allowsAnimation; + } + + public function setAllowsAnimation(bool $allows): static + { + $this->allowsAnimation = $allows; + return $this; + } }