Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Image Manipulation Package for setting Opaqueness?

by t0mas (Priest)
on Mar 07, 2001 at 14:32 UTC ( [id://62708]=note: print w/replies, xml ) Need Help??


in reply to Image Manipulation Package for setting Opaqueness?

To get the RGB of a pixel with PerlMagick, you can use:
($red,$green,$blue,$opaque) = split(/,/,$image->Get("pixel[$x,$y]"));
Update: After some thougth I came up with this to solve your first problem:
#!/usr/bin/perl -w use strict; use Image::Magick; # Simuate background webcam picture... :) my $image1 = Image::Magick->new; $image1->Set(size=>'100x100'); $image1->ReadImage('xc:black'); $image1->Draw(stroke=>'green', primitive=>'rectangle', points=>'5,5 95 +,95'); # Textbackground image my $image2 = Image::Magick->new; $image2->Set(size=>'100x20'); $image2->ReadImage('xc:blue'); # Make composite image of background and a 60.5 % transparent text-bac +kground $image1->Composite(compose=>'Blend', image=>$image2, x=>0, y=>0, opaci +ty=>60.5); # Add un-transparent text atop on background $image1->Annotate(font=>'@c:/windows/fonts/arial.ttf', pointsize=>15, +stroke=>'red', text=>'Whoo',x=>30,y=>15,fill=>'red'); # Write image $image1->Write('x.png');
Update 2: It seems that newer versions (>5.25) of IM have replaced the Blend command with Dissolve and wants the opacity to be an integer...

/brother t0mas

Replies are listed 'Best First'.
Re: Re: Image Manipulation Package for setting Opaqueness?
by keith (Novice) on Mar 07, 2001 at 15:42 UTC
    I found a "Composite" function I can use with PerlMagick to take images and layer them onto an original image. With that, you can select an opacity as well. I could create an image with the desired background color and then use a Composite and select an opacity, but that seems a little odd.
Re: Re: Image Manipulation Package for setting Opaqueness?
by keith (Novice) on Mar 07, 2001 at 16:53 UTC
    I tried this example code you posted and I couldn't get it working since it seems like the compose mode "Blend" is nonexistant with the current release of Perl/ImageMagick. I tried using "Dissolve" with somewhat of the desired effect, but the opacity seems to be about 75 or so even if I set it to 1 or 100....
      Just downloaded the latest version of Image::Magick and it seems like the Blend function was removed....
      I use Image::Magick version 5.25 and perl 5.6 (on Win32) and the code runs just fine with that combination :).


      /brother t0mas
        Blend seems to be replaced with Dissolve for the newer version at least. Your test code works fine...just like I was picturing. Thank you.

        However, I couldn't get the "arial.ttf" font to work. I tried copying over the font many ways from my windows machine to my linux machine (ftp, samba, etc) so I don't think that's the problem. If I change the font parameter to something like "fixed", it works fine, printing "Whoo", but it can't seem to find the arial.ttf (even when i do './arial.ttf'). Maybe linux has a fonts folder similar to c:\windows\fonts that I don't know about...?

        When I load the GUI for ImageMagick and try to manually draw a font, it gives me a huge font list with fonts seemingly already installed. It doesn't say which folder it's in and won't let me escape the folder to select other fonts. Also, none seem to have a ttf extention.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found