Page 1 of 1

help with transparency

Posted: 2014-09-09T07:38:15-07:00
by danmc
I'm building up an image that consists of a background along with several photos arranged on top. I am getting the background with:

$imgfile = "background.jpg";
($width, $height, $size, $format) = $image->Ping($imgfile);
print "$width x $height, size = $size, format = $format\n";
$image->Resize(width=>$page_w, height=>$page_h);

and then at the very end of my program:


before writing it out.

What I'd like is to make my background image partially transparent with white behind it. I'm having troubles understanding how this is done with perl magick.

Any suggestions?


Re: help with transparency

Posted: 2014-09-11T11:24:04-07:00
by danmc
I'll answer my own question after a good bit of messing around.

The key seems to be to make the image that I want to be partially transparent a 'png' when reading it in. It is OK that the file is jpeg.

# need the png bit here
my $backimage = Image::Magick->new(magick=>'png');
my $image = Image::Magick->new();

# set up background
$image->Resize(width=>$page_w, height=>$page_h);

$backimage->Resize(width=>$page_w, height=>$page_h);

my $rc = $image->Composite(
gravity => "Center",
image => $backimage,
opacity => '50%', #how much transparency
tile => 1,

On a related note, is there a better source of documentation than ... manipulate

For example the section under Composite list the parameters like compose=> but gives no description of what any mean. I'm finding it hard to learn the Perl API.


Re: help with transparency

Posted: 2014-09-11T13:58:56-07:00
by fmw42
I do not know about PerlMagick documentation, but I would suggest you find similar names for functions and settings from the command line tools.

see ... ptions.php