Skip to content

Commit

Permalink
Fix bug when loading png greyscale type
Browse files Browse the repository at this point in the history
turn image into rgb if colorspace if other than CMYK, RGB, HSL or HSV.
this prevents working on greyscale colorspace images when loading from
PNG color type greyscale format.
  • Loading branch information
olivervogel committed Aug 11, 2024
1 parent 5d5cf35 commit 6196ff1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Drivers/Imagick/Decoders/NativeObjectDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

class NativeObjectDecoder extends SpecializableDecoder implements SpecializedInterface
{
protected const SUPPORTED_COLORSPACES = [
Imagick::COLORSPACE_SRGB,
Imagick::COLORSPACE_CMYK,
Imagick::COLORSPACE_HSL,
Imagick::COLORSPACE_HSB,
];

public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_object($input)) {
Expand All @@ -34,6 +41,13 @@ public function decode(mixed $input): ImageInterface|ColorInterface
$input = $input->coalesceImages();
}

// turn image into rgb if colorspace if other than CMYK, RGB, HSL or HSV.
// this prevents working on greyscale colorspace images when loading
// from PNG color type greyscale format.
if (!in_array($input->getImageColorspace(), self::SUPPORTED_COLORSPACES)) {
$input->setImageColorspace(Imagick::COLORSPACE_SRGB);
}

// create image object
$image = new Image(
$this->driver(),
Expand Down

0 comments on commit 6196ff1

Please sign in to comment.