Page 1 of 1

Setting TrueColor on Grayscale JPEG

Posted: 2012-06-17T03:51:28-07:00
by Madnesz
When loading a greyscale image into memory, it is automatically changed into image type to 2 (GrayScale). As I cannot use greyscale JPG's in further processing, I need to keep its original image type 6 (TrueColor). However, I cannot find any working method to do so. Here's what I get when loading a greyscale JPG which originally has a 24 bit depth, but after using ImageMagick is changed to 8 bit depth.

$img = new Imagick();
$img->readImage($source);
$img->setImageType(6);
echo $img->getImageType();

Still outputs 2. Is this a bug or a design choice? If it's a design choice, is there any workaround?

Please note that saving the image to file, also produces an 8 bit depth photo, so it's not just the getImageType() function.

Re: Setting TrueColor on Grayscale JPEG

Posted: 2012-06-17T04:58:08-07:00
by Madnesz
Fixed it! The key was to use:

$img = new Imagick();
$img->setType(6); (instead of $img->setImageType() after loading the image)
$img->readImage($source);

It now outputs an image of type 6.