Page 1 of 1

Mask with input image <256 colors/bug?

Posted: 2013-01-04T09:17:02-07:00
by davidfooks
Hi,

I'm running

Code: Select all

convert input.png -mask mask.png -fill red -draw "rectangle 0,0,512,512" out.png
Which runs fine with input images >256 colors. However, if I try to run an image with <256 colors I always get a transparent background as the output.

All I want to be able to do is convert the source image so that this no longer happens. However, I've tried adding -type TrueColor and -colorspace RGB but neither fix this.

If I output debugging information the only different lines are:

Code: Select all

<<<<<<< Working >256 image
      Reading PNG bKGD chunk.
2013-01-04T16:02:12+00:00 0:00.010 0.000u 6.6.9 Coder convert[11703]: png.c/ReadOnePNGImage/2101/Coder
      raw ping_background=(255,255,255).
2013-01-04T16:02:12+00:00 0:00.010 0.000u 6.6.9 Coder convert[11703]: png.c/ReadOnePNGImage/2125/Coder
      bkgd_scale=257.
2013-01-04T16:02:12+00:00 0:00.010 0.000u 6.6.9 Coder convert[11703]: png.c/ReadOnePNGImage/2128/Coder
      ping_background=(65535,65535,65535).
2013-01-04T16:02:12+00:00 0:00.010 0.000u 6.6.9 Coder convert[11703]: png.c/ReadOnePNGImage/2145/Coder
      image->background_color=(65535,65535,65535).
2013-01-04T16:02:12+00:00 0:00.010 0.000u 6.6.9 Coder convert[11703]: png.c/ReadOnePNGImage/2383/Coder
===============
>>>>>>>>>>Broken <256 Image

...

<<<<<<< Working >256 image
No room in the colormap to add background color
===============
background_color index is 232
>>>>>>>>>>Broken <256 Image

...

<<<<<<< Working >256 image
number_opaque          > 256
===============
number_opaque          = 232
>>>>>>>>>>Broken <256 Image
Any ideas?

Re: Mask with input image <256 colors/bug?

Posted: 2013-01-04T11:58:04-07:00
by fmw42
Please post links to your input and mask files, so others can test.

You can try adding PNG8:output and see if that helps.

Or adding -colors 256 and/or -type palette.

Otherwise, the PNG developer will need to check and would need your images.

Re: Mask with input image <256 colors/bug?

Posted: 2013-01-07T03:34:00-07:00
by davidfooks
I've tried adding -colors and -type but with no change.

Ok, the command I'm running is:

Code: Select all

convert input1.png -mask mask.png -fill red -draw "rectangle 0,0,256,256" out1.png
convert input2.png -mask mask.png -fill red -draw "rectangle 0,0,256,256" out2.png
With the following files
input1:
Image
input2:
Image
mask:
Image

And the output I get is
out1:
Image
Which doesn't look right

out2:
Image
That's how it should look.

If I add a second color to the input inside of the mask
input3:
Image

and run:

Code: Select all

convert input3.png -mask mask.png -fill red -draw "rectangle 0,0,256,256" out3.png
I get this
out3:
Image
So now its correct!

Note that if the color is outside of the mask then I still get out1.

Re: Mask with input image <256 colors/bug?

Posted: 2013-01-07T10:26:25-07:00
by davidfooks
Oh and I'm running Ubuntu 12 with ImageMagick 6.6.9-7 Q16

Re: Mask with input image <256 colors/bug?

Posted: 2013-01-07T10:54:03-07:00
by snibgo
I'm not familiar with this style of mask, but putting +mask before the output filename may give the results you want.

Re: Mask with input image <256 colors/bug?

Posted: 2013-01-07T11:04:28-07:00
by fmw42
On my IM 6.8.1.9 Q16 Mac OSX Snow Leopard, I get the following:

convert input1.png -mask mask.png -fill red -draw "rectangle 0,0,256,256" out1.png

Image


or if I negate the mask

convert mask.png -negate mask2.png
convert input1.png -mask mask2.png -fill red -draw "rectangle 0,0,256,256" out1b.png

Image


So I suspect it is your older version of IM that needs an upgrade.

Re: Mask with input image <256 colors/bug?

Posted: 2013-01-08T08:56:17-07:00
by davidfooks
Ok I'll try updating.

The images you show there are still incorrect. It should look like out2 or out3, a red circle around the original image.

Re: Mask with input image <256 colors/bug?

Posted: 2013-01-08T09:01:19-07:00
by davidfooks
Nope updating didn't help :( just get the same output running ImageMagick 6.8.1-9 2013-01-08 Q16

Re: Mask with input image <256 colors/bug?

Posted: 2013-01-08T09:21:55-07:00
by snibgo
Have you tried my "+mask" suggestion? I think it gives the result you want (in v6.7.9).

Re: Mask with input image <256 colors/bug?

Posted: 2013-01-08T11:44:29-07:00
by fmw42
davidfooks wrote:Ok I'll try updating.

The images you show there are still incorrect. It should look like out2 or out3, a red circle around the original image.
I think your mask circle is larger than the circle in the images, so it will also keep some of the background white.

Re: Mask with input image <256 colors/bug?

Posted: 2013-01-09T03:52:36-07:00
by davidfooks
fmw42 wrote:
davidfooks wrote:Ok I'll try updating.

The images you show there are still incorrect. It should look like out2 or out3, a red circle around the original image.
I think your mask circle is larger than the circle in the images, so it will also keep some of the background white.
Yup, its supposed to do that. out1 should look like out3 but without the blue circle.

Thanks snibgo. I needed to add +mask at the end. The docs for this are terrible. The correct operation is:

Code: Select all

convert input1.png -mask mask.png -fill red -draw "rectangle 0,0,256,256" +mask out1.png
Does anybody you know why I need to do this +mask? Or why convert doesn't force you to specify it by throwing a warning

Re: Mask with input image <256 colors/bug?

Posted: 2013-01-09T08:43:48-07:00
by snibgo
As I said, I'm not familiar with this method of masking, but it seems to me that "-mask" remains in effect until "+mask", and that the effect of "-mask" is more than just preventing updates to pixels.