help with transparency

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
danmc
Posts: 8
Joined: 2014-09-08T18:18:38-07:00
Authentication code: 6789

help with transparency

Post 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->ReadImage($imgfile);
$image->Rotate(-90);
$image->Resize(width=>$page_w, height=>$page_h);


and then at the very end of my program:

$image->Composite(image=>$appended,compose=>'over');

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?

Thanks
-Dan
danmc
Posts: 8
Joined: 2014-09-08T18:18:38-07:00
Authentication code: 6789

Re: help with transparency

Post 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->ReadImage('xc:white');
$image->Resize(width=>$page_w, height=>$page_h);

$backimage->ReadImage("background.jpg");
$backimage->Resize(width=>$page_w, height=>$page_h);


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


On a related note, is there a better source of documentation than
http://www.imagemagick.org/script/perl- ... 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.

-Dan
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: help with transparency

Post 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
http://www.imagemagick.org/script/comma ... ptions.php
http://www.imagemagick.org/script/compose.php
http://www.imagemagick.org/Usage/compose/
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
Post Reply