Mask with input image <256 colors/bug?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
davidfooks
Posts: 6
Joined: 2013-01-04T08:12:01-07:00
Authentication code: 6789

Mask with input image <256 colors/bug?

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
davidfooks
Posts: 6
Joined: 2013-01-04T08:12:01-07:00
Authentication code: 6789

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

Post 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.
Last edited by davidfooks on 2013-01-08T09:05:23-07:00, edited 2 times in total.
davidfooks
Posts: 6
Joined: 2013-01-04T08:12:01-07:00
Authentication code: 6789

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

Post by davidfooks »

Oh and I'm running Ubuntu 12 with ImageMagick 6.6.9-7 Q16
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

I'm not familiar with this style of mask, but putting +mask before the output filename may give the results you want.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
davidfooks
Posts: 6
Joined: 2013-01-04T08:12:01-07:00
Authentication code: 6789

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

Post 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.
davidfooks
Posts: 6
Joined: 2013-01-04T08:12:01-07:00
Authentication code: 6789

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

Post by davidfooks »

Nope updating didn't help :( just get the same output running ImageMagick 6.8.1-9 2013-01-08 Q16
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

Have you tried my "+mask" suggestion? I think it gives the result you want (in v6.7.9).
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
davidfooks
Posts: 6
Joined: 2013-01-04T08:12:01-07:00
Authentication code: 6789

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

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply