Hi,
Unfortunately Imager doesn't apply the mask from the image to the color data, which results in the black background.
I'll look at changing that for 0.60, since the current behaviour is confusing.
In the meantime, I've included a simple program that will apply the mask to the image. You could adapt this for use in your code.
#!perl -w
use strict;
use Imager;
my $in = shift;
my $out = shift
or die "Usage: $0 input output\n";
my $im = Imager->new;
$im->read(file => $in)
or die "Cannot read $in:", $im->errstr;
my $format = $im->tags(name => 'i_format');
$format =~ /^(ico|cur)$/
or die "Input not a ico or cure image\n";
my $mask = $im->tags(name => "${format}_mask");
# Imager always uses * for the 1s
# add an alpha channel
$im = $im->convert(preset => 'addalpha');
my @mask = split /\n/, $mask;
shift @mask; # lose the key
for my $y (0 .. $im->getheight() - 1) {
my $m = shift @mask;
for my $x (0 .. $im->getwidth() - 1 ) {
if (substr($m, $x, 1) eq '*') {
my $c = $im->getpixel(x => $x, 'y' => $y);
$im->setpixel(x => $x, 'y' => $y, color => Imager::Color->new(($c->rgba)[0,1,2], 0));
}
}
}
$im->write(file => $out)
or die "Cannot write $out: ", $im->errstr;
|