1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-21 13:11:18 +02:00

Change colorspace adjustment logic

This commit is contained in:
Oliver Vogel
2024-08-11 13:41:19 +02:00
parent e7554ec048
commit 9deb50b0bc

View File

@@ -17,13 +17,6 @@ use Intervention\Image\Modifiers\RemoveAnimationModifier;
class NativeObjectDecoder extends SpecializableDecoder implements SpecializedInterface 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 public function decode(mixed $input): ImageInterface|ColorInterface
{ {
if (!is_object($input)) { if (!is_object($input)) {
@@ -41,10 +34,10 @@ class NativeObjectDecoder extends SpecializableDecoder implements SpecializedInt
$input = $input->coalesceImages(); $input = $input->coalesceImages();
} }
// turn image into rgb if colorspace if other than CMYK, RGB, HSL or HSV. // turn images with colorspace 'GRAY' into 'SRGB' to avoid working on
// this prevents working on greyscale colorspace images when loading // greyscale colorspace images as this results images loosing color
// from PNG color type greyscale format. // information when placed into this image.
if (!in_array($input->getImageColorspace(), self::SUPPORTED_COLORSPACES)) { if ($input->getImageColorspace() == Imagick::COLORSPACE_GRAY) {
$input->setImageColorspace(Imagick::COLORSPACE_SRGB); $input->setImageColorspace(Imagick::COLORSPACE_SRGB);
} }