Page 1 of 1

force color PNGs

Posted: 2010-07-06T09:39:37-07:00
by check227
Howdy,

First let me say, I've already found and reviewed the posts: Trouble forcing TrueColorMatte and -type command not working
However, I'm still having the same issue where images with no color content are being saved as grayscale. I can use the IM command line tools to force PNGs to save as TrueColor however I'm using a python api for MagickWand. Its my own variation of the project here.

My code is preforming the following steps:

Code: Select all

wand=api.NewMagickWand()
api.MagickReadImage(wand, "allGrayImage.png")
api.MagickSetImageFormat(wand, "png24")
api.MagickSetImageDepth(wand, 8)
api.MagickSetImageType(wand, TRUE_COLOR_TYPE)
print api.MagickGetImageType(wand)
api.MagickWriteImage(wand, "pleaseBeColor.png")
The value of TRUE_COLOR_TYPE is 6, however the value that is printed is 2 for GrayscaleType. Likewise the saved image's colorspace is grayscale as reported by KDE file properties, Krita and - most importantly - ffmpeg which doesn't seem to like grayscale PNG images. Is there something I'm missing here? Thanks.

Re: force color PNGs

Posted: 2010-07-06T20:24:08-07:00
by anthony
Assuming I understand your needs....

Many times IM will try to determine the best type when saving the image. However their are controls that are passed to the coder to force it to save to specific types rather than letting it 'guess'.
See http://www.imagemagick.org/Usage/formats/#png_write
for some of these controls.

The full details of the settings/defines are in the coder/png.c source.

Re: force color PNGs

Posted: 2010-07-07T08:38:40-07:00
by check227
Okay thanks very much I've got it working. The piece I was ignorant of was the MagickSetOption method. Now my code does the following:

Code: Select all

wand=api.NewMagickWand()
api.MagickReadImage(wand, "allGrayImage.png")
api.MagickSetImageType(wand, TRUE_COLOR_TYPE)
api.MagickSetOption(wand, "png:color-type", 6) # or 2 for RGB no alpha
api.MagickWriteImage(wand, "nowColorImage.png")
Thanks again.