Page 1 of 1

Cutting part from image with a mask

Posted: 2007-09-15T08:44:39-07:00
by defied
Hello,

I've been trying to get this to work all afternoon, I thought it would be simple but I can't get it to work :(
I have a .png mask, the black part of the mask indicates the area I want from a transparent .gif

First I make a tile of images and save it in a .gif with transparency:

Code: Select all

convert -background None -size 373x280 tile:heart.png tile.gif
Image

Then I have this mask:
Image

The black area needs to be filled with the heart tiles, while the rest needs to remain transparent.
But this is what happens:

Code: Select all

convert tile.gif mask.png -compose CopyOpacity -composite -matte output.gif
Image

So it's almost good, but the black color needs to be transparent. I know I can remove it with -transparent but if the tile.gif happens to have black in it it would remove too much. Can someone help me extract a part from a transparent gif and save it in a transparent png?

Re: Cutting part from image with a mask

Posted: 2007-09-15T08:58:34-07:00
by defied
Ok well, I found the solution:

Code: Select all

composite -compose Dst_In mask.png tile.gif -matte output.gif

Re: Cutting part from image with a mask

Posted: 2007-09-20T12:38:35-07:00
by defied
Does someone know how I can make a mask look cleaner?

Right now I have this:

Image

but the little white dots in the right lower corner should be replaced with black, that way I can get a clean mask without any holes or noise.

Thanks

Re: Cutting part from image with a mask

Posted: 2007-09-20T12:56:36-07:00
by Bonzo
How are you creating your mask ?

If you are using a colour would adding a -fuzz help?

Re: Cutting part from image with a mask

Posted: 2007-09-21T08:32:29-07:00
by defied
the mask is a transparent png which I receive by flash's bitmapdata.. I tried various stuff but did not come up with a solution.
I'll keep looking and post here if I find a solution.

Re: Cutting part from image with a mask

Posted: 2007-09-24T20:27:00-07:00
by anthony
To clean your mask, first -draw fill the outside area with some color.

now overlay the mask on black to fill in the 'holes'

You can now replace the original fill color with thransparency again.

To smooth the result blur it with -channel RGBA setting, and threshold the result.