Imager->_set_error("'other' parameter required to create alpha fill");
return;
}
- unless (eval { $other_fill->isa("Imager::Fill") }) {
- Imager->_set_error("'other' parameter must be an Imager::Fill object to create an alpha fill");
- return;
+ unless (ref $other_fill &&
+ eval { $other_fill->isa("Imager::Fill") }) {
+ # try to auto convert to a fill object
+ if (ref $other_fill && $other_fill =~ /HASH/) {
+ $other_fill = Imager::Fill->new(%$other_fill)
+ or return;
+ }
+ else {
+ undef $other_fill;
+ }
+ unless ($other_fill) {
+ Imager->_set_error("'other' parameter must be an Imager::Fill object to create an alpha fill");
+ return;
+ }
}
my $raw_fill = $other_fill->{fill};
#!perl -w
use strict;
-use Test::More tests => 143;
+use Test::More tests => 148;
use Imager ':handy';
use Imager::Fill;
is_fcolor4($out->getpixel(x => 6, y => 3, type => "float"),
0, 0.25, 0, 1, "check drawn against background at 6,3");
}
+ ok(!Imager::Fill->new(type => "opacity"),
+ "should fail to make an opacity fill with no other fill object");
+ is(Imager->errstr, "'other' parameter required to create alpha fill",
+ "check error message");
+ ok(!Imager::Fill->new(type => "opacity", other => "xx"),
+ "should fail to make an opacity fill with a bad other parameter");
+ is(Imager->errstr, "'other' parameter must be an Imager::Fill object to create an alpha fill",
+ "check error message");
+
+ # check auto conversion of hashes
+ ok(Imager::Fill->new(type => "opacity", other => { solid => "FF0000" }),
+ "check we auto-create fills")
+ or print "# ", Imager->errstr, "\n";
}
sub color_close {