semi-transparent pixels

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
dsl
Posts: 21
Joined: 2008-01-22T15:14:29-07:00

semi-transparent pixels

Post by dsl »

Hello all.

I have the following situation.

Background image is transparent PNG image.
Image its self in JPG format.
Mask in PNG format.

I try to do a composite.

convert background.png image.jpg mask.png -composite result.png

But I lose semi-transparency this way.
If I use white background there is no problem.

Could you please advise, how I can save semi-trasparent pixels when composite ?
dsl
Posts: 21
Joined: 2008-01-22T15:14:29-07:00

Re: semi-transparent pixels

Post by dsl »

Please, could anybody advise?

Here are images that I use in composite:
Mask
Image

Result with transparent background
Image

Result with white background
Image

Notice, when transparent background is used, edges are not smooth.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: semi-transparent pixels

Post by fmw42 »

Post your source images as well as the mask.

Generally the background and overlay (first and second) images are not transparent. You may want to review

http://www.imagemagick.org/Usage/compose/

and

http://www.imagemagick.org/Usage/channels/#masks
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: semi-transparent pixels

Post by anthony »

I believe you have a very old ImageMagick. The 3 image masked composition was a boolean or binary up until Im version 6.3.4-11.

But there are lots of ways to skin that cat!

One alternative is to take the first image, and use the mask to shape that image before overlaying it on your background.

Examples of this is
http://imagemagick.org/Usage/compose/#copyopacity
http://imagemagick.org/Usage/fonts/#mask
http://imagemagick.org/Usage/channels/#masks
Especially the example immediateally before that last.

Another method is to directly use the mask (probably negated) to just make the areas you want white white, by using a 'screen' composition. More on this is..
http://imagemagick.org/Usage/compose/#screen
http://imagemagick.org/Usage/channels/#compose
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply