force greyscale image to sRGB
Posted: 2018-12-13T00:53:28-07:00
I am hoping someone can help, as I'm a little bit stuck with some code.
From the command line, I can take an input PNG file, convert it to TIF and force it to sRGB using the following:
and it outputs a TIF file with:
colorspace:13 (Imagick::COLORSPACE_SRGB)
type:6 (Imagick::IMGTYPE_TRUECOLOR)
When I run the following code via PHP
I get an image that is greyscale:
colorspace:2 (Imagick::COLORSPACE_GRAY)
type:2 (Imagick::IMGTYPE_GRAYSCALE)
I'm running ImageMagick 6.9.7-4 Q16 x86_64 20170114.
The input file is an RGB PNG, but its contents is greyscale.
Have I done something wrong, or missed something obvious?
From the command line, I can take an input PNG file, convert it to TIF and force it to sRGB using the following:
Code: Select all
convert in.png -colorspace srgb -type truecolor out.tif
colorspace:13 (Imagick::COLORSPACE_SRGB)
type:6 (Imagick::IMGTYPE_TRUECOLOR)
When I run the following code via PHP
Code: Select all
$img = new Imagick();
$img->readImage('in.png');
$img->transformImageColorspace(\Imagick::COLORSPACE_RGB);
$img->setImageType(\Imagick::IMGTYPE_TRUECOLOR);
$img->setImageFormat('tiff');
// there's a reason I am using file_put_contents, not writeImage(), but assume it has no impact with this issue.
file_put_contents('out.tif', $img);
colorspace:2 (Imagick::COLORSPACE_GRAY)
type:2 (Imagick::IMGTYPE_GRAYSCALE)
I'm running ImageMagick 6.9.7-4 Q16 x86_64 20170114.
The input file is an RGB PNG, but its contents is greyscale.
Have I done something wrong, or missed something obvious?