Overlaying images discarded the transparency
authorAlexander Ebert <ebert@woltlab.com>
Mon, 11 Apr 2022 15:05:49 +0000 (17:05 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 11 Apr 2022 15:05:49 +0000 (17:05 +0200)
See https://www.woltlab.com/community/thread/295124-imagickimageadapter-overlayen-zweier-bilder-mit-alpha-channel-entfernt-transpare/

wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php

index bd62d899e8d6551e11521014df8242ee7f451a7a..f2e9d0d2d624615c4201aab9077b997fb12ec08c 100644 (file)
@@ -418,6 +418,12 @@ class ImagickImageAdapter implements IImageAdapter, IWebpImageAdapter
             throw new SystemException("Image '" . $file . "' is not readable or does not exist.", 0, '', $e);
         }
 
+        // Explicitly enable transparency if the target image has transparent pixels,
+        // otherwise the background color is replaced by #ffffff.
+        if ($this->imagick->getImageAlphaChannel()) {
+            $this->imagick->setImageBackgroundColor('transparent');
+        }
+
         $overlayImage->evaluateImage(\Imagick::EVALUATE_MULTIPLY, $opacity, \Imagick::CHANNEL_OPACITY);
 
         if ($this->imagick->getImageFormat() == 'GIF') {