diff --git a/src/Imagick/Image.php b/src/Imagick/Image.php index 6ad80607..995c099f 100644 --- a/src/Imagick/Image.php +++ b/src/Imagick/Image.php @@ -958,10 +958,11 @@ private function applyFastLinear(Linear $fill) * Sets colorspace and image type, assigns the palette. * * @param \Imagine\Image\Palette\PaletteInterface $palette + * @param bool $convert * * @throws \Imagine\Exception\InvalidArgumentException */ - private function setColorspace(PaletteInterface $palette) + private function setColorspace(PaletteInterface $palette, $convert) { $typeMapping = array( // We use Matte variants to preserve alpha @@ -973,24 +974,13 @@ private function setColorspace(PaletteInterface $palette) PaletteInterface::PALETTE_RGB => defined('\Imagick::IMGTYPE_TRUECOLORALPHA') ? \Imagick::IMGTYPE_TRUECOLORALPHA : (defined('\Imagick::IMGTYPE_TRUECOLORMATTE') ? \Imagick::IMGTYPE_TRUECOLORMATTE : 7), PaletteInterface::PALETTE_GRAYSCALE => defined('\Imagick::IMGTYPE_GRAYSCALEALPHA') ? \Imagick::IMGTYPE_GRAYSCALEALPHA : (defined('\Imagick::IMGTYPE_GRAYSCALEMATTE') ? \Imagick::IMGTYPE_GRAYSCALEMATTE : 3), ); - if (!isset(static::$colorspaceMapping[$palette->name()])) { throw new InvalidArgumentException(sprintf('The palette %s is not supported by Imagick driver', $palette->name())); } - - $this->imagick->setType($typeMapping[$palette->name()]); - $this->imagick->setColorspace(static::$colorspaceMapping[$palette->name()]); - if ($this->imagick->getnumberimages() > 0 && defined('Imagick::ALPHACHANNEL_REMOVE') && defined('Imagick::ALPHACHANNEL_SET')) { - $originalImageIndex = $this->imagick->getiteratorindex(); - foreach ($this->imagick as $frame) { - if ($palette->supportsAlpha()) { - $frame->setimagealphachannel(\Imagick::ALPHACHANNEL_SET); - } else { - $frame->setimagealphachannel(\Imagick::ALPHACHANNEL_REMOVE); - } - } - $this->imagick->setiteratorindex($originalImageIndex); - } + $typeID = $typeMapping[$palette->name()]; + $colorspaceID = static::$colorspaceMapping[$palette->name()]; + $this->imagick->setType($typeID); + $this->imagick->setcolorspace($colorspaceID); $this->palette = $palette; }