Skip to content

Commit

Permalink
ENH Remove animation for thumbnails by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Jul 11, 2024
1 parent 0b20ec7 commit 1fc6810
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions code/Model/ThumbnailGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -65,6 +66,8 @@ class ThumbnailGenerator
*/
private static $method = 'FitMax';

private bool $allowsAnimation = false;

/**
* Generate thumbnail and return the "src" property for this thumbnail
*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 1fc6810

Please sign in to comment.