June 14th, 2011, 02:36 PM
MagickWand Opacity issue
I have a script that essentially builds a picture of a cat. All images are .png files.
A user can choose the base color, then add markings to the cat. They can also set colors for the markings. The outline is then layered on.
The problem I'm running into is I would like to remove some opacity from the markings. Currently, the person can change the color of the marking, then layer it onto the base. BUT, I would like that marking to be able to fade by a percentage the user chooses.
I tried to use MagickSetImageOpacity() for this, however, it ended up changing the opacity of the ENTIRE image instead of the area that wasn't already transparent.
I'm pretty sure this is the wrong function to use. The only solution I can really think of is iterating through the index or pixels and changing the transparency that way (I've never done that, so that's just a theory). This sounds like a HUGE waste of server resources, though.
I have attached a base, outline, and marking. I have also attached one completed image WITHOUT setting opacity, and a screenshot of the form where I attempted to set the opacity on the Giraffe marking.
As you can see, the Giraffe marking became a solid color and obliterated any layers below it.
To reiterate, it SHOULD have instead set the opacity of any colored pixels to 10% of what they were. The background transparency should have been left alone.
Sorry if this is confusing; ask any questions and I'll try to clear things up!
June 14th, 2011, 05:40 PM
You lost me in there, but I think you're saying that you want one part of an image made transparent and another not?
What about using two images: one for the markings (you change this one's transparency) and the other for the not-markings.
June 14th, 2011, 06:32 PM
The marking is already transparent to a point: the background of it is transparent, with the content inside it being either opaque or translucent. I want to change the content's transparency so less of it shows (ie, I want the marking to become lighter when it is layered onto the base).
This will allow players to have more subtle markings that, when layered with other markings, will allow multiple markings to display.
June 17th, 2011, 10:23 PM
June 18th, 2011, 03:27 AM
I don't know the magick functions, but it sounds like your looking for the equivalent of the GD function imagecopymerge function, particularly for the pct parameter which allows you to copy an image at a specified opacity level.
Browsing the docs on php.net for a bit, sounds like the following might be close:
$base = new Imagick('base.png');
$marks = new Imagick('marks.png');
$base->compositeImage($marks, imagick::COMPOSITE_COPY|imagick::COMPOSITE_COPYOPACITY , 0, 0, imagick::CHANNEL_ALL);
Recycle your old CD's, don't just trash them
If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
June 18th, 2011, 11:11 PM
Yup, that would be the equivalent of imagecopymerge. I've used GD quite a bit, but my client uses MagickWand and wants to continue using it
Unfortunately, that will not quite work since it is MagickWand x.x I found the same function in MagickWand, however, it does not allow transparency.
Back to the drawing board for me I guess, haha. Thanks for trying
January 13th, 2012, 12:17 AM
Still frustrated with this :S
I have to revisit this code again and get the opacity per layer working.
I'm hoping a fresh pair of eyes could offer some insight? At this point, I'm even willing to PayPal some $ for a solution to my problem.
Again, the client does not want to change from ImageMagick. (*sigh*)
Thanks in advance!!
October 1st, 2012, 08:09 AM
I stumbled across this post while researching on Google the same thing you are looking for: How to produce a functioning image generator that layers images with the correct transparencies.
I just wanted to say I feel your pain! I'm trying to keep up with other dog games on the web and add a script that dynamically generates the picture of a dog based on what colors/markings it was born with. It's been a frustrating process. I can layer the images just fine but the anti-aliasing and transparency have been giving me a fight.
You mentioned GD, I'm going to look into that. I've shelved this image generator idea for two years because of hitting a wall, but you mentioned GD, so I'm going to look into what that is. Maybe it will help me.
I never go on this site anymore but if you want to bounce ideas off each other send me an email. I'll message you my email address right after this post.