Apply layer mask w/ transparent result?

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
StayPuft
Posts: 6
Joined: 2012-07-08T18:17:39-07:00
Authentication code: 13

Apply layer mask w/ transparent result?

Post by StayPuft » 2012-07-08T18:26:20-07:00

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.

User avatar
fmw42
Posts: 25657
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Apply layer mask w/ transparent result?

Post by fmw42 » 2012-07-08T18:38:08-07:00

try reversing the order of your images

StayPuft
Posts: 6
Joined: 2012-07-08T18:17:39-07:00
Authentication code: 13

Re: Apply layer mask w/ transparent result?

Post by StayPuft » 2012-07-08T18:41:53-07:00

Placing the mask first gives me the mask as the result.

User avatar
fmw42
Posts: 25657
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Apply layer mask w/ transparent result?

Post by fmw42 » 2012-07-08T18:54:08-07:00

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

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Apply layer mask w/ transparent result?

Post by anthony » 2012-07-08T19:15:08-07:00

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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

StayPuft
Posts: 6
Joined: 2012-07-08T18:17:39-07:00
Authentication code: 13

Re: Apply layer mask w/ transparent result?

Post by StayPuft » 2012-07-08T19:17:38-07:00

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.

StayPuft
Posts: 6
Joined: 2012-07-08T18:17:39-07:00
Authentication code: 13

Re: Apply layer mask w/ transparent result?

Post by StayPuft » 2012-07-08T19:29:46-07:00

Updated to ImageMagick 6.7.8-2 2012-07-04 Q16 and still no change.

StayPuft
Posts: 6
Joined: 2012-07-08T18:17:39-07:00
Authentication code: 13

Re: Apply layer mask w/ transparent result?

Post by StayPuft » 2012-07-08T19:59:42-07:00

None of my PNGs had an alpha channel, so I did:

convert -alpha transparent image.png image.png

This fixed it.

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Apply layer mask w/ transparent result?

Post by anthony » 2012-07-08T21:34:21-07:00

That just makes the image transparent! I can;'t see how that fixes things!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

StayPuft
Posts: 6
Joined: 2012-07-08T18:17:39-07:00
Authentication code: 13

Re: Apply layer mask w/ transparent result?

Post by StayPuft » 2012-07-09T17:31:29-07:00

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.

Post Reply