*/
protected $supportsWritingAnimatedGIF = true;
+ /**
+ * List of image format that support animations.
+ */
+ protected static array $animatedFormats = ['GIF', 'WEBP'];
+
/**
* Creates a new ImagickImageAdapter.
*/
// fix height/width for animated gifs as getImageHeight/getImageWidth
// returns the height/width of ONE frame of the animated image,
// not the "real" height/width of the image
- if ($this->imagick->getImageFormat() == 'GIF') {
+ if (\in_array($this->imagick->getImageFormat(), self::$animatedFormats)) {
$imagick = $this->imagick->coalesceImages();
$this->height = $imagick->getImageHeight();
{
$thumbnail = clone $this->imagick;
- if ($thumbnail->getImageFormat() == 'GIF') {
+ if (\in_array($thumbnail->getImageFormat(), self::$animatedFormats)) {
$thumbnail = $thumbnail->coalesceImages();
do {
*/
public function clip($originX, $originY, $width, $height)
{
- if ($this->imagick->getImageFormat() == 'GIF') {
+ if (\in_array($this->imagick->getImageFormat(), self::$animatedFormats)) {
$this->imagick = $this->imagick->coalesceImages();
do {
*/
public function resize($originX, $originY, $originWidth, $originHeight, $targetWidth, $targetHeight)
{
- if ($this->imagick->getImageFormat() == 'GIF') {
+ if (\in_array($this->imagick->getImageFormat(), self::$animatedFormats)) {
$image = $this->imagick->coalesceImages();
foreach ($image as $frame) {
// draw text
$draw->annotation($x, $y, $text);
- if ($this->imagick->getImageFormat() == 'GIF') {
+ if (\in_array($this->imagick->getImageFormat(), self::$animatedFormats)) {
$this->imagick = $this->imagick->coalesceImages();
do {
$overlayImage->evaluateImage(\Imagick::EVALUATE_MULTIPLY, $opacity, \Imagick::CHANNEL_OPACITY);
- if ($this->imagick->getImageFormat() == 'GIF') {
+ if (\in_array($this->imagick->getImageFormat(), self::$animatedFormats)) {
$this->imagick = $this->imagick->coalesceImages();
do {
throw new \LogicException("Unreachable");
}
+ if ($image->getImageFormat() == 'WEBP' && $filename != 'webp') {
+ $sourceImage = $image;
+ $image = new \Imagick();
+ foreach ($sourceImage as $frame) {
+ $image->addImage($frame->getImage());
+ break;
+ }
+ }
+
$image->writeImages("{$fileFormat}:{$filename}", true);
}