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?