Skip to content
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

Conversation

GuySartorelli
Copy link
Member

@GuySartorelli GuySartorelli commented Jul 11, 2024

@@ -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')) {
Copy link
Member Author

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)

@GuySartorelli GuySartorelli force-pushed the pulls/3/remove-animation-for-thumbnails branch 2 times, most recently from 6056770 to fc13971 Compare July 11, 2024 03:17
Copy link
Member

@emteknetnz emteknetnz left a 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

@GuySartorelli GuySartorelli force-pushed the pulls/3/remove-animation-for-thumbnails branch 2 times, most recently from f49d2d7 to c32badc Compare July 17, 2024 22:33
@GuySartorelli
Copy link
Member Author

Swapped sample gif to one we explicitly own

@GuySartorelli GuySartorelli force-pushed the pulls/3/remove-animation-for-thumbnails branch from c32badc to 0e65505 Compare July 21, 2024 23:54
Comment on lines +116 to +128
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;
}
}
}
Copy link
Member Author

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.

@GuySartorelli GuySartorelli force-pushed the pulls/3/remove-animation-for-thumbnails branch from 0e65505 to 2586b54 Compare July 22, 2024 01:03
@emteknetnz emteknetnz merged commit 29bcbaf into silverstripe:3 Jul 23, 2024
12 checks passed
@emteknetnz emteknetnz deleted the pulls/3/remove-animation-for-thumbnails branch July 23, 2024 04:26
emteknetnz pushed a commit to creative-commoners/silverstripe-asset-admin that referenced this pull request Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants