1

When saving a RGB image to a PNG with Imagick. The image gets saved automatically in grayscale when it contains only grey pixels. I understand this a default stetting, that can be overridden. I would like to save my image always in RGB as a default. How do I turn Imagick's auto-grayscale off with PHP/Imagick? I wrote this code.

$im = new Imagick();
$im->setResolution(288,288);
$im->setColorspace(Imagick::COLORSPACE_SRGB);
$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->readImage($orgDataPath);
$im->setoption("colorspace:auto-grayscale", "off");
$im->setImageType(Imagick::IMGTYPE_TRUECOLOR);
$im->trimImage(0);
$im->setImageFormat("png");
$im->writeImage($pngPrint.".png");
// cleanup
$im->clear();
$im->destroy();
Martin
  • 22,212
  • 11
  • 70
  • 132
Bobby Solo
  • 53
  • 7
  • 1
    [`$im->transformimagecolorspace(imagick::COLORSPACE_RGB);`](https://www.php.net/manual/en/imagick.transformimagecolorspace.php) ? – Syscall Jan 07 '22 at 10:44
  • 1
    does [this question](https://stackoverflow.com/questions/29781436/prevent-imagemagick-converting-to-grayscale) help you? – Martin Jan 07 '22 at 10:46
  • Thanks @martin, I've read this and also tried saving as a PNG32 and incorporated Truecolor. I couldn't get it working for me. – Bobby Solo Jan 07 '22 at 10:56
  • @syscall this unfortunately causes my code to throw an error. – Bobby Solo Jan 07 '22 at 10:56
  • @BobbySolo could you update your question with all the things you've tried so far else we will suggest things you've already done and that slows down finding a working solution. Thanks `:-)` – Martin Jan 07 '22 at 12:58

0 Answers0