Fixed resizing of animated gifs
authorMarcel Werk <burntime@woltlab.com>
Sun, 18 Dec 2016 11:06:11 +0000 (12:06 +0100)
committerMarcel Werk <burntime@woltlab.com>
Sun, 18 Dec 2016 11:06:11 +0000 (12:06 +0100)
wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php

index 51b55802905ff5814e2e0a3100450a8b3254ac05..78815582f07b1cda6c735dae3df951a0e24f0a2b 100644 (file)
@@ -165,9 +165,22 @@ class ImagickImageAdapter implements IImageAdapter {
         * @inheritDoc
         */
        public function resize($originX, $originY, $originWidth, $originHeight, $targetWidth, $targetHeight) {
-               $this->clip($originX, $originY, $originWidth, $originHeight);
-               
-               $this->imagick->resizeImage($targetWidth, $targetHeight, \Imagick::FILTER_POINT, 0);
+               if ($this->imagick->getImageFormat() == 'GIF') {
+                       $image = $this->imagick->coalesceImages();
+                       
+                       foreach ($image as $frame) {
+                               $frame->cropImage($originWidth, $originHeight, $originX, $originY);
+                               $frame->thumbnailImage($targetWidth, $targetHeight);
+                               $frame->setImagePage($targetWidth, $targetHeight, 0, 0);
+                       }
+                       
+                       $this->imagick = $image->deconstructImages();
+               }
+               else {
+                       $this->clip($originX, $originY, $originWidth, $originHeight);
+                       
+                       $this->imagick->resizeImage($targetWidth, $targetHeight, \Imagick::FILTER_POINT, 0);
+               }
        }
        
        /**