Page 1 of 1

Apply layer mask w/ transparent result?

Posted: 2012-07-08T18:26:20-07:00
by StayPuft
I'm trying to apply a layer mask and remove the background from an image with transparency, and to the best of my understanding, this command should do it.

Code: Select all

composite -compose CopyOpactiy image.png mask.png result.png 
However, it just spits out the image, unchanged.

Image
Image

The desired result should have the black areas of the mask replaced with transparency.

Re: Apply layer mask w/ transparent result?

Posted: 2012-07-08T18:38:08-07:00
by fmw42
try reversing the order of your images

Re: Apply layer mask w/ transparent result?

Posted: 2012-07-08T18:41:53-07:00
by StayPuft
Placing the mask first gives me the mask as the result.

Re: Apply layer mask w/ transparent result?

Posted: 2012-07-08T18:54:08-07:00
by fmw42
This works fine for me using more current IM 6 syntax. Note your images were converted from png to jpg upon uploading. Thus any alpha channel in either would have been lost. So if you are using PNG or gif or any image format that supports transparency for either of your image, you need to disable the alpha channel by using -alpha off or the older form +matte. That could be your problem apart from the wrong image order.


convert oql5nnojqmlyivxglah7_thumb.png.jpeg 87es0okco191h7vozvgn_thumb.png.jpeg -alpha off -compose copy_opacity -composite 1tmp1.png

so does this

composite -compose copy_opacity +matte 87es0okco191h7vozvgn_thumb.png.jpeg oql5nnojqmlyivxglah7_thumb.png.jpeg 1tmp2.png

I am using IM 6.7.8.2 Q16 Mac OSX Snow Leopard. You never said what version of IM you are using and what platform. Perhaps you need an upgrade

Look carefully at the syntax at http://www.imagemagick.org/Usage/compose/#compose

The image order needs to be swapped between the convert syntax and the composite syntax. Your mask image is not the same as the "mask" image in the documentation. It is just the overlay image. You only the third image is really the "mask" image

Re: Apply layer mask w/ transparent result?

Posted: 2012-07-08T19:15:08-07:00
by anthony
Add -alpha off before the composition operation.

If the source image has alpha, the alpha will be used rather than the grayscale values from the image.

Re: Apply layer mask w/ transparent result?

Posted: 2012-07-08T19:17:38-07:00
by StayPuft
Those commands still don't work for me. Same results. Looks like there's a new binary out, I'll give that a try.

ImageMagick 6.7.7-2 2012-05-25 Q16 on Windows 7 x64.

Re: Apply layer mask w/ transparent result?

Posted: 2012-07-08T19:29:46-07:00
by StayPuft
Updated to ImageMagick 6.7.8-2 2012-07-04 Q16 and still no change.

Re: Apply layer mask w/ transparent result?

Posted: 2012-07-08T19:59:42-07:00
by StayPuft
None of my PNGs had an alpha channel, so I did:

convert -alpha transparent image.png image.png

This fixed it.

Re: Apply layer mask w/ transparent result?

Posted: 2012-07-08T21:34:21-07:00
by anthony
That just makes the image transparent! I can;'t see how that fixes things!

Re: Apply layer mask w/ transparent result?

Posted: 2012-07-09T17:31:29-07:00
by StayPuft
Well, I don't know how to explain it, but I ran that transparent command on about 700 images, and then ran

composite -compose copy_opacity mask.png image.png result.png

They all came out with transparent backgrounds. Best guess is that running that command added an alpha channel to the images.

Edit: Nevermind... I have maya installed and currently all my PNGs are assosciated with fcheck... for some reason it still shows parts of the image that other viewers don't display... very strange.