Skip to content

Commit

Permalink
- rotate()s back parameter now accepts color names like other methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Cook committed Feb 11, 2006
1 parent f794f00 commit c9304f9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions Imager/Changes
Expand Up @@ -1345,6 +1345,7 @@ Revision history for Perl extension Imager.
- the search for freetype1.x headers is now smarter
- add tests for scaleX()/scaleY()
- expand documentation of scaleX()/scaleY()
- rotate()s back parameter now accepts color names like other methods

=================================================================

Expand Down
11 changes: 9 additions & 2 deletions Imager/Imager.pm
Expand Up @@ -2116,9 +2116,16 @@ sub rotate {
elsif (defined $opts{radians} || defined $opts{degrees}) {
my $amount = $opts{radians} || $opts{degrees} * 3.1415926535 / 180;

my $back = $opts{back};
my $result = Imager->new;
if ($opts{back}) {
$result->{IMG} = i_rotate_exact($self->{IMG}, $amount, $opts{back});
if ($back) {
$back = _color($back);
unless ($back) {
$self->_set_error(Imager->errstr);
return undef;
}

$result->{IMG} = i_rotate_exact($self->{IMG}, $amount, $back);
}
else {
$result->{IMG} = i_rotate_exact($self->{IMG}, $amount);
Expand Down
19 changes: 17 additions & 2 deletions Imager/t/t64copyflip.t
@@ -1,7 +1,7 @@
#!perl -w
use strict;
use lib 't';
use Test::More tests=>57;
use Test::More tests => 61;
use Imager;

#$Imager::DEBUG=1;
Expand Down Expand Up @@ -70,7 +70,22 @@ ok($rimg, "rotate with background gave us an image");
if (!$rimg->write(file=>"testout/t64_rot10_back.ppm")) {
print "# Cannot save: ",$rimg->errstr,"\n";
}


{
# rotate with text background
my $rimg = $img->rotate(degrees => 45, back => '#FF00FF');
ok($rimg, "rotate with background as text gave us an image");

# check the color set correctly
my $c = $rimg->getpixel(x => 0, 'y' => 0);
is_deeply([ 255, 0, 255 ], [ ($c->rgba)[0, 1, 2] ],
"check background set correctly");

# check error handling for background color
$rimg = $img->rotate(degrees => 45, back => "some really unknown color");
ok(!$rimg, "should fail due to bad back color");
cmp_ok($img->errstr, '=~', "^No color named ", "check error message");
}

my $trimg = $img->matrix_transform(matrix=>[ 1.2, 0, 0,
0, 1, 0,
Expand Down

0 comments on commit c9304f9

Please sign in to comment.