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:
@@ -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(),
|
||||
|
Reference in New Issue
Block a user