Subject: | crop outside of an image |
Say the image is 100x100, if you crop outside the image, ->crop returns
an empty image (ie, one w/o ->{IMG}) but not undef
$src->crop( top=>1000, bottom=>1500, left=>0, right=>100 )
diff -rub Imager-0.54.ORIG/Imager.pm Imager-0.54/Imager.pm
--- Imager-0.54.ORIG/Imager.pm 2006-09-14 03:30:23.000000000 -0400
+++ Imager-0.54/Imager.pm 2007-06-08 16:35:17.000000000 -0400
@@ -754,7 +754,10 @@
$self->_set_error("resulting image would have no content");
return;
}
-
+ if( $r < $l or $b < $t ) {
+ $self->_set_error("attempting to crop outside of the image");
+ return;
+ }
my $dst = $self->_sametype(xsize=>$r-$l, ysize=>$b-$t);
i_copyto($dst->{IMG},$self->{IMG},$l,$t,$r,$b,0,0);
diff -rub Imager-0.54.ORIG/t/t65crop.t Imager-0.54/t/t65crop.t
--- Imager-0.54.ORIG/t/t65crop.t 2006-08-07 02:37:35.000000000 -0400
+++ Imager-0.54/t/t65crop.t 2007-06-08 16:42:05.000000000 -0400
@@ -1,7 +1,7 @@
#!perl -w
use strict;
use lib 't';
-use Test::More tests => 60;
+use Test::More tests => 64;
require "t/testtools.pl";
use Imager;
@@ -171,3 +171,13 @@
cmp_ok($warning, '=~', 'void', "correct warning");
cmp_ok($warning, '=~', 't65crop\\.t', "correct file");
}
+
+{
+ my $src = test_oo_img();
+ ok(!$src->crop( top=>1000, bottom=>1500, left=>0, right=>100 ),
+ "outside of image" );
+ cmp_ok($src->errstr, '=~', qr/outside of the image/, "and message");
+ ok(!$src->crop( top=>100, bottom=>1500, left=>1000, right=>1500 ),
+ "outside of image" );
+ cmp_ok($src->errstr, '=~', qr/outside of the image/, "and message");
+}