B&W SVG -> PNG results in pseudoclass

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
adrianj

B&W SVG -> PNG results in pseudoclass

Post by adrianj »

I would really appreciate some help with forcing RGB when converting an SVG file. All work fine by default so long as there is more than just black in the vector. But if only black, the resulting PNG becomes Gray/8 (photoshop) or 8-bit PseudoClass 256c (IM identify). It seems that the Pseudo is the problem – all the color ones show 8-bit DirectClass.

I have:

$imagickImage->setImageFormat(“png32″);
$imagickImage->setImageDepth(8);

and then I have tried adding either:
$imagickImage->setImageType(7); //TrueColor
$imagickImage->setImageColorSpace(1); //RGB

OR

$imagickImage->setImageType imagick::IMGTYPE_TRUECOLOR);
$imagickImage->setImageColorSpace(imagick::COLORSPACE_RGB);

Can you please clarify if it is ColorSpace or Colorspace (or does it not matter) and also whether I should be using the text or numerical values to set the space and type.

Is there something else I should be doing to force RGB and DirectClass so that it won’t automatically convert it to Grayscale. I need the PNGs to be DirectClass so that TCPDF can properly show them, otherwise it messes up the image.

Maybe this is an Imagemagick problem in general (so maybe I should post on a more general board), because from some other reading it sounds like some older versions didn't automatically convert to pseudoclass just because there is no colors present.

Thanks,
Adrian
adrianj

Re: B&W SVG -> PNG results in pseudoclass

Post by adrianj »

Not really solved, but managed a workaround - see here:
viewtopic.php?f=1&t=15444&p=54655#p54655
adrianj

Re: B&W SVG -> PNG results in pseudoclass

Post by adrianj »

Finally solved. Might have been a few issues going on, some to do with reporting by identify and others my own fault.

Here is the code that finally worked:

Code: Select all

		clearstatcache();
		$imagickImage = new Imagick();
		$imagickImage->setBackgroundColor(new ImagickPixel("transparent"));
		$imagickImage->readImage($path_to_svg);  
		$imagickImage->setImageFormat("png32");
		$imagickImage->setImageDepth(8);
		$imagickImage->setImageColorSpace(imagick::COLORSPACE_RGB);		
		$imagickImage->setImageType(imagick::IMGTYPE_TRUECOLORMATTE);
		$imagickImage->setOption("png:color-type","6");
		clearstatcache();		
		$imagickImage->scaleImage(150,0);
		$imagickImage->writeImage($path_to_png);
		$imagickImage->clear();
		$imagickImage->destroy();
Note that the order is important and also that the imagemagick command line "identify" does not correctly show truecolormatte, even in debug mode. pngcheck -v however does work.

Note also that I upgraded to 6.5.9-1 (beta at the moment), because of a fix applied that is mentioned here:
viewtopic.php?f=3&t=15445

Also worth a read is my post to the main imagemagick board:
viewtopic.php?f=1&t=15444

Hope that helps someone else.
Post Reply