Skip to content

Commit

Permalink
Fix colorspace conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mlocati committed Oct 18, 2021
1 parent 0086456 commit fbe586b
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/Imagick/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down

0 comments on commit fbe586b

Please sign in to comment.