-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH Remove animation for thumbnails by default. #1475
ENH Remove animation for thumbnails by default. #1475
Conversation
code/Model/ThumbnailGenerator.php
Outdated
@@ -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')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note it doesn't make sense to add the RemoveAnimation
method to AssetContainer
interface, because it's about image manipulation.
Even though that interface is only used by DBFile
and File
which both use the ImageManipulation
trait, we shouldn't assume the object has this method for the sake of strict correctness. (even though below we assume it has whatever $method
is lol)
6056770
to
fc13971
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be some future issue with copyright with that sample image provided, swap it to something more "sample image" like
f49d2d7
to
c32badc
Compare
Swapped sample gif to one we explicitly own |
c32badc
to
0e65505
Compare
if (!$this->getAllowsAnimation()) { | ||
if (ClassInfo::hasMethod($file, 'getImageBackend')) { | ||
/** @var Image_Backend $backend */ | ||
$backend = $file->getImageBackend(); | ||
$origAllowAnimation = $backend->getAllowsAnimationInManipulations(); | ||
$backend->setAllowsAnimationInManipulations(false); | ||
} elseif ($file->getIsAnimated() && ClassInfo::hasMethod($file, 'RemoveAnimation')) { | ||
$noAnimation = $file->RemoveAnimation(); | ||
if ($noAnimation) { | ||
$file = $noAnimation; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1475 (comment) - this is now more complex logic, but that principle remains that we should adhere to the API of the AssetContainer
interface. As such I've provided two ways to do this - one where there's an Image_Backend
available and one where that's not available but RemoveAnimation()
is.
0e65505
to
2586b54
Compare
Needs silverstripe/silverstripe-assets#621 for CI to go green.
Issue