Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Image::Magick

by roberto (Acolyte)
on Nov 11, 2000 at 18:47 UTC ( [id://41091]=perlquestion: print w/replies, xml ) Need Help??

roberto has asked for the wisdom of the Perl Monks concerning the following question:

I wold like to take an image, insert a new layer (a gif with a trasparent background), merge the 2 layers and save all as a new image (gif or jpeg)
my problem is: only the upper layer is visible in the resulting image, the transparent part of the upper layer completely hide the background layer. How can i do this preservig transparency?

Replies are listed 'Best First'.
(jcwren) RE: Image::Magick
by jcwren (Prior) on Nov 11, 2000 at 19:24 UTC
    roberto, I don't know the answer to your question, but www.imagemagick.org has a lot of resources.

    There's a number of examples and discussions available, and searching the bug tracking system for some of your keywords may find sample code that people have posted to demonstrate a problem (pay close attention to the bug searching process. It spits out partial pages, and is not always evident whether it's completed or not. Make sure the browser indicates it's done before assuming the search did not complete).

    You might also check what revision you have installed. I found a pretty glaring bug in the 5.2.2 release pertaining to color to monochrome conversion, and a lot of people had problems with format conversion. It would be my last resort, but don't *completely* discount a ImageMagick bug, especially in the 5.2.2 release.

    Also, if you have the ImageMagick tarball installed, I believe there is a directory that contains some various examples that may be worth looking at.

    I do know from the little I've done with ImageMagick that transparent layers always seem to be a pain. I don't know enough general behavior about them to say 'Oh, you need to do this'.

    --Chris

    e-mail jcwren
Re: Image::Magick
by OeufMayo (Curate) on Dec 03, 2000 at 16:36 UTC

    The code below should do the trick.
    However, I'm looking for a way to make the image over transparent to 50%. It doesn't seem to work with the 'Over' compose method. The only way to do it would be to create a PNG with an alpha transparency set to 50%, but I can't find a way to make one with Image::Magick or GD. Has anyone have an idea?

    $image_over->Read("over.gif"); $image_under->Read("under.jpg"); $image_over->Transparent("white"); # Set the transp. color $image_under->Composite( compose => 'Over', opacity => 50, # Doesn't seem to work with 'Over' x => 20, y => 25, image => $image_over, ) ; $image_under->Write("Composite.jpg");
    <kbd>--
    PerlMonger::Paris(http => 'paris.pm.org');</kbd>
      The ImageMagick documentation is quite... unimpressive.

      Having said that, I stared at http://www.simplesystems.org/ImageMagick/www/combine.html for a few minutes and decided that I would suggest using "atop" rather than "over", for no apparent reason other than that's the way I always am forced to work with ImageMagick... trial and error. {grin}

      It's so sad that such a great tool has such lousy documentation. I've used it for only a half dozen tasks or so, and three times have had to go to the source code to get my answer for simple things.

      -- Randal L. Schwartz, Perl hacker

        I cannot believe that--after weeks of sweat--I came to nearly the same conclusion as a Perl icon.

        ("Nearly", because without Mr. Schwartz's deep-and-wide experience, I could not recognize that the documentation was "unimpressive." I thought it "sucked.")

        I had come to the same conclusion that the PerlMagick module (a depressingly confusing synonym for Image::Magick) is best designed for "trial and error."

        Here's the thing: what I have always loved-loved-loved about Perl is that when I know what I want to do, there's Perl, right there with more than one way to do it. I know what I want to do with Image::Magick--and that isn't helping much at all.

        I'll ask it in a new ticket, but what I'd like to do is interrogate the Image::Magick module, and whatever is associated with it (however that's done) and ask it to spit out Just What Methods I can use, and Just What Parameters they take.

        Thank you Mr. Schwartz. Your comment here gives me new hope that I maybe ain't crazy. (And thanks for the PP book--which I paid retail for, probably back when it cost about-seven-fifty. Sorry I'm late with the thanks, but I had no idea how to get ahold of you.)

      Update: Actually, I've found the way to achieve the effect I wanted, so if anyone's interrested, here's the code you have to add just before the call to Transparent:

      $CD_map->MatteFloodfill( x => $x_inside, y => $y_inside, matte => 90);

      Where $x_inside and $y_inside are the coordinates of a point inside the polygone you want to make translucid. the value of matte is set to 90 here, but it seems to be more or less the same than 50% transparency...

      Anyway, it's a real good way to dynamically paint area in a graphic file, once the hassle of compiling Image::Magick for Win32 is finished!

Re: Image::Magick
by elwarren (Priest) on Nov 12, 2000 at 05:33 UTC
    Make sure the transparency color is the same in both images. I don't know how you do this with the Image::Magick code, but if they don't match up you may have to do some pallet juggling.

    Wish I had more info.
Re: Image::Magick
by meetn2veg (Scribe) on Sep 05, 2003 at 15:12 UTC
    I'm having a similar problem re transparencies etc...

    I have a Cº logo set as a background image on their site. What I'm trying to do is load a transparent *.gif file, write (annotate: user input) a message to the *.gif file, and eventually display the annotated *.gif over the logo image in order for it to be clickable (put within DIV and HREF it). If I get this sussed, I'll also be looking into morphing it or animating it - so something... (probably just leave it as is!).

    I too have visited ImageMagick.org and have found it confusing - http://shawn.apocabilly.org/PGP/ (O'Reilley) slightly less confusing as there are examples (which I've been pulling apart with only moderate success!!) and there's little else I've managed to find out.

    Hopefully someone out there has the know-how...

    Eagerly awaiting,
    Richard.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://41091]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-18 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found