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

I have been attempting to write a script using Image::Magick that will place one image on top of another image. Everything works fine except I cannot figure out a way to control to opacity level of the top image. My intention is to be able to speicify how see through the top image (watermark) is. The way it works now is it is completely opaque except for any color that is white. I can make that transparent but not translucent. so many attributes, so little time! There is an opacity attribut i can pass in to the Composite function but only seems to affect the background image? I need to alter the top image's opacity.
my $background=Image::Magick->new(magick=>"gif"); $background->BlobToImage($binary_data); my $foreground=Image::Magick->new; $foreground->Read($watermark_file); $foreground->Transparent(color=>"white"); $background->Composite(compose=>'Over', Image=>$foreground, x=> 1, + y=> 1) $background->Write("gif-"); $binary_data = $background->ImageToBlob(); print "content-type: image/gif\n\n"; print $binary_data;
thanks for the help ahead of time.

Replies are listed 'Best First'.
Re: Image::magick visible watermark help
by valdez (Monsignor) on Jun 24, 2004 at 15:10 UTC

    Try using 'Plus' composition option, for example:

    #!/usr/bin/perl use Image::Magick; use LWP::Simple; LWP::Simple::mirror('http://s.a.cnn.net/si/features/2004_swimsuit/imag +es/gallery/popup/may_03.jpg', './base.jpg'); $base = Image::Magick->new(); $base->Read('./base.jpg'); ($width, $height) = $base->Get('width', 'height'); $watermark = Image::Magick->new(); $watermark->Set(size => "${width}x${height}"); $watermark->ReadImage('xc:white'); $watermark->Transparent( color => white ); $watermark->Annotate(pointsize => 36, fill => 'red', text => '1st Italian Perl Workshop\nPisa, 19 + e 20 Luglio 2004', gravity => 'center'); $watermark->Composite(image => $base, compose => 'Plus', gravity => 'Center'); $watermark->Write('./composition.jpg'); $watermark->Display;

    Ciao, Valerio

      to make it work with an image use a png-8 image that is a light colored logo and transparent by design. then have it outlined in a more standoutish color. that solved the problem for me. it appears the original code worked fine but my image choice was messing the display up. Thanks UPDATE=== downvoted bc why...that is the solution