Page 1 of 1

MagickSetImageOpacity behavior

Posted: 2007-02-06T08:57:14-07:00
by aidynskas
Hi,

Anoyne could explain me how do I accomplish layer opacity settings similar to Photoshop/GIMP? PNG and PSD files load just fine with their corresponding opacity values. However what I want to do is control their % opacity like 0%,34%,100%,etc. Unfortunately MagickSetImageOpacity has no effect if i call it on image, that has matte enabled (nothing happens from visual perspective at least). Disabling matte and then setting the opacity does the work exactly how I want it to be done, but matte channel is lost and black garblish around the image appears.

Anyone has suggestions how to accomplist what I want?

Thanks a lot!

Re: MagickSetImageOpacity behavior

Posted: 2007-02-06T09:23:46-07:00
by magick
Are you using a normalized value such as MagickSetImageOpacity(..., 0.34) for 34% transparency?

Re: MagickSetImageOpacity behavior

Posted: 2007-02-06T11:17:39-07:00
by aidynskas
Yes, the value is in range of [0;1]. I will code some quick example on how it works and add it soon.

Re: MagickSetImageOpacity behavior

Posted: 2007-02-06T11:39:48-07:00
by aidynskas
Here is the complete sample code:

Code: Select all

MagickWand *magick_wand=NewMagickWand();
	MagickReadImage(magick_wand,"/test.png");
		
	MagickSetImageOpacity(magick_wand,0.5);

	MagickWriteImage(magick_wand,"/result.png");
1. The test.png image can be found at http://www.jumsoft.com/images/test.png
2. Result image with matte setting unchanged can be found at http://www.jumsoft.com/images/result_matteistrue.png
3. Result image with matte setting changed to false can be found at http://www.jumsoft.com/images/result_matteisfalse.png

Any ideas?

Thanks a lot,
Aidas

Re: MagickSetImageOpacity behavior

Posted: 2007-02-06T12:46:40-07:00
by magick
We can reproduce the problem and will have a fix in the latest release of ImageMagick by tommorrow. Thanks.

Re: MagickSetImageOpacity behavior

Posted: 2007-02-06T14:22:53-07:00
by aidynskas
Great news!

Thank you very much!

Re: MagickSetImageOpacity behavior

Posted: 2007-03-12T10:56:35-07:00
by aidynskas
magick wrote: We can reproduce the problem and will have a fix in the latest release of ImageMagick by tommorrow. Thanks.


Sorry for bumping this post, but I wonder if the bug is fixed yet (I've installed latest version and it seems that the problem is still there)?

Maybe I could help identifying the problem?

Re: MagickSetImageOpacity behavior

Posted: 2007-03-19T20:51:17-07:00
by anthony
The problem is that that function is only used to initialize a matte channel, when none exists. I know I just looked at the code for another problem.

I gather you just want to half the opacity of an existing image, that already has some transparency. If so you best use some channel limits function to multiply the alpha values by .5

On the command line that would be "-channel A -evaluate divide 2"
You could also use a Composite Dissolve function too, which does similar alpha channel modifications before overlaying images.

Sorry I do not know magick++ to help you code in in that API.

Re: MagickSetImageOpacity behavior

Posted: 2008-02-05T14:42:11-07:00
by mrBlaQ
The equivalent MagickWand PHP syntax is the following

Code: Select all

MagickEvaluateImage($wnd, MW_DivideEvaluateOperator, (100/$alpha), MW_AlphaChannel);

Re: MagickSetImageOpacity behavior

Posted: 2008-02-05T17:43:50-07:00
by anthony
You could also use Multiply too, assuming that $alpha is a percentage.

Code: Select all

MagickEvaluateImage($wnd, MW_MultiplyEvaluateOperator, ($alpha/100), MW_AlphaChannel);
That avoids any chance of a division by zero error.