Help me with composite and Inverse transparency

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
kocoten1992
Posts: 3
Joined: 2015-05-27T14:28:09-07:00
Authentication code: 6789

Help me with composite and Inverse transparency

Post by kocoten1992 »

Hi,

I've searching and I found this viewtopic.php?t=18842, but the image is gone, so please answer this again :D

Got 3 image below, layer1.png, layer2.png and result.png repsectively.

How could I produce the result (it is layer2 over layer1, but I got stuck at the end, when cutting the transparency).

Important note: the layer 1 could be white as well.

Many thanks :D

Image

Image

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

Re: Help me with composite and Inverse transparency

Post by fmw42 »

The image you uploaded or is being downloaded is in JPG format and has lost any transparency from the PNG original.

If you have the png original where the gray in layer 2 is transparent, then this is one way. There may be other more efficient methods.

Code: Select all

convert layer1.png \( layer2.png -alpha extract -negate \) -compose copy_opacity -composite layer3.png
The above is unix syntax. For windows do

Code: Select all

convert layer1.png ( layer2.png -alpha extract -negate ) -compose copy_opacity -composite layer3.png
kocoten1992
Posts: 3
Joined: 2015-05-27T14:28:09-07:00
Authentication code: 6789

Re: Help me with composite and Inverse transparency

Post by kocoten1992 »

fmw42 wrote:The image you uploaded or is being downloaded is in JPG format and has lost any transparency from the PNG original.

If you have the png original where the gray in layer 2 is transparent, then this is one way. There may be other more efficient methods.
...
Thanks you very much :D , one more question, how this can be achive in php ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help me with composite and Inverse transparency

Post by fmw42 »

one more question, how this can be achive in php ?
Just use the exec() function to enclose the same command.

Code: Select all

<?php
exec("convert layer1.png \( layer2.png -alpha extract -negate \) -compose copy_opacity -composite layer3.png 2>&1",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>
If you mean PHP Imagick, then you need to ask that on the Imagick forum below. I am not an Imagick user. Note that Imagick is not being kept current with Imagemagick and is not as full functioned. So PHP exec() is going to do the job all the time easily for a single IM command line.
Post Reply