#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Location
    Minnesota, USA
    Posts
    96
    Rep Power
    10

    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!
    Attached Images
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,113
    Rep Power
    9398
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Location
    Minnesota, USA
    Posts
    96
    Rep Power
    10
    Not quite.

    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.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Location
    Minnesota, USA
    Posts
    96
    Rep Power
    10
    Any insight, anyone...?
  8. #5
  9. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,952
    Rep Power
    4033
    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:
    PHP Code:
    $base = new Imagick('base.png');
    $marks = new Imagick('marks.png');
    $marks->SetOpacity(0.25);
    $base->compositeImage($marksimagick::COMPOSITE_COPY|imagick::COMPOSITE_COPYOPACITY 00imagick::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
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Location
    Minnesota, USA
    Posts
    96
    Rep Power
    10
    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
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Location
    Minnesota, USA
    Posts
    96
    Rep Power
    10

    Unhappy 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!!
  14. #8
  15. GIRL POWER!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    235
    Rep Power
    0
    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.

IMN logo majestic logo threadwatch logo seochat tools logo