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

Has anyone seen "Oculus", a webcam program for the Macintosh?

It has a mode where you can overlay text on the webcam images (such as date and time or a caption). The interresting thing is that it has a mode for setting different opaquenesses for the "text background". This creates a very interresting, professional looking effect and I can't seem to produce it with GD or PerlMagick (ImageMagick). I've seen other packages for Perl that offer something that sounds like it may handle opaqueness, but before I start filling my system with these modules, I'd like to find out if there's a way to do it with PerlMagick. I also noticed that PerlMagick doesn't have a "GetPixel" type of function for returning the RGB or Hex code of a pixel's color value. Is there a way to do this with PerlMagick?

Thank you.
  • Comment on Image Manipulation Package for setting Opaqueness?

Replies are listed 'Best First'.
Re: Image Manipulation Package for setting Opaqueness?
by t0mas (Priest) on Mar 07, 2001 at 14:32 UTC
    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
      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.
      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