Using a feathered mask to cut out a part of an image

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
tasslehawf
Posts: 3
Joined: 2014-01-28T23:07:37-07:00
Authentication code: 6789

Using a feathered mask to cut out a part of an image

Post by tasslehawf »

This is the effect that I'm going for. I thought I wanted to create an "alpha" image to do the cut. Not sure now.

http://mhayesdesign.com/help_with_mask_cut.jpg

I'm using rmagick. I though that was what I was going for:
source = mask = Magick::Image.read("source_image.jpg")
mask = Magick::Image.read("mask_image.jpg")
source.composite!(mask, Magick::CenterGravity, Magick::OutCompositeOp)

I was trying to load the mask as a transparency, but it seems to flattening it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using a feathered mask to cut out a part of an image

Post by fmw42 »

To use an image as an alpha channel, you need to use the equivalent of -compose copy_opacity to put (composite) the image into the alpha channel of the image. The composite the new image with alpha channel over the background image. Sorry I do not know Rmagick.

see
http://www.imagemagick.org/Usage/compose/#compose
http://www.imagemagick.org/Usage/compose/#copyopacity
tasslehawf
Posts: 3
Joined: 2014-01-28T23:07:37-07:00
Authentication code: 6789

Re: Using a feathered mask to cut out a part of an image

Post by tasslehawf »

Even with the command line tool, I can't make it work at all in any visible way.
Here's the "alpha" image:
http://mhayesdesign.com/ahl_alpha.png

And the image I want to mask:
http://mhayesdesign.com/4308129_64_close.jpg
fmw42 wrote:To use an image as an alpha channel, you need to use the equivalent of -compose copy_opacity to put (composite) the image into the alpha channel of the image. The composite the new image with alpha channel over the background image. Sorry I do not know Rmagick.

see
http://www.imagemagick.org/Usage/compose/#compose
http://www.imagemagick.org/Usage/compose/#copyopacity
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using a feathered mask to cut out a part of an image

Post by fmw42 »

try this

convert 4308129_64_close.jpg ahl_alpha.png -alpha off -compose copy_opacity -composite result1.png

or if you want the other part to show

convert 4308129_64_close.jpg \( ahl_alpha.png -negate \) -alpha off -compose copy_opacity -composite result2.png

On windows, use


convert 4308129_64_close.jpg ( ahl_alpha.png -negate ) -alpha off -compose copy_opacity -composite result2.png
tasslehawf
Posts: 3
Joined: 2014-01-28T23:07:37-07:00
Authentication code: 6789

Re: Using a feathered mask to cut out a part of an image

Post by tasslehawf »

I've noticed a weird behavior. If I chose a name for the resulting image that's based on the name of the source image, the composition just gives me the source image. If I chose something else, like: blah.png. It works. All things the same, the file name is the only thing I'm changing.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using a feathered mask to cut out a part of an image

Post by fmw42 »

tasslehawf wrote:I've noticed a weird behavior. If I chose a name for the resulting image that's based on the name of the source image, the composition just gives me the source image. If I chose something else, like: blah.png. It works. All things the same, the file name is the only thing I'm changing.
Give me an example command line. That should not be happening. Also post links to your images if you can, so others can test. You can upload your images to say dropbox (public folder) and put links here.
Post Reply