1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-17 19:26:25 +02:00

Fix bug when loading png greyscale type

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.
This commit is contained in:
Oliver Vogel
2024-08-11 11:38:33 +02:00
parent 5d5cf355e4
commit 6196ff1eb9

View File

@@ -17,6 +17,13 @@ use Intervention\Image\Modifiers\RemoveAnimationModifier;
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)) {
@@ -34,6 +41,13 @@ class NativeObjectDecoder extends SpecializableDecoder implements SpecializedInt
$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(),