[magick-users] perlmagick: making parts transparent using a mask
Anthony Thyssen
A.Thyssen at griffith.edu.au
Sat Jun 6 03:03:17 PDT 2009
On Fri, 5 Jun 2009 23:32:19 +0100
Lex Thoonen <Lex at peng.nl> wrote:
| Hi Magick-users,
|
| I'd like to create a transparent png with perlmagick from this file:
|
| http://www.allesoversterrenkunde.nl/fotos/temp/aardebolletje3.png
|
| using this file as a mask:
|
| http://www.allesoversterrenkunde.nl/test/images/aardebolletje-mask.png
|
| so only the earth stays visible.
|
| I've tried lots but I don't get it to work...
|
| Any ideas?
That is dead easy!!!
Look at the PerlMagick 'demo' directory that should be installed on
your system and match it up against the command line handling
http://www.imagemagick.org/Usage/compose/#copyopacity
The trick is to make sure the mask has no ALPHA channel enabled
so IM copies the grayscale into the image, rather than the alpha
channel itself!
=======8<--------CUT HERE----------axes/crowbars permitted---------------
#!/bin/perl
#
# Command Line equivelence
# convert aardebolletje3.png aardebolletje-mask.png \
# +matte -compose CopyOpacity -composite \
# -write show: earth.png
#
use strict;
use Image::Magick;
my $earth=Image::Magick->new();
$earth->Read("aardebolletje3.png");
my $mask=Image::Magick->new();
$mask->Read("aardebolletje-mask.png");
$mask->Set(alpha=>"Off");
$earth->Composite(
image=$mask,
compose='CopyOpacity',
);
$earth->Write('show:');
$earth->Write('earth.png');
=======8<--------CUT HERE----------axes/crowbars permitted---------------
Anthony Thyssen ( System Programmer ) <A.Thyssen at griffith.edu.au>
-----------------------------------------------------------------------------
Dungeons and Dragons Famous Last Words:
"C'mon DM, let's see some REAL monsters!"
-----------------------------------------------------------------------------
Anthony's Home is his Castle http://www.cit.gu.edu.au/~anthony/
More information about the Magick-users
mailing list