]> git.imager.perl.org - imager.git/commitdiff
- cropping outside the image would return an Imager object with
authorTony Cook <tony@develop=help.com>
Tue, 12 Jun 2007 14:14:08 +0000 (14:14 +0000)
committerTony Cook <tony@develop=help.com>
Tue, 12 Jun 2007 14:14:08 +0000 (14:14 +0000)
   no low-level image object, instead of returning false.
   Fixed by: Philip Gwyn (Leolo)
   http://rt.cpan.org/Ticket/Display.html?id=27509

Changes
Imager.pm
t/t65crop.t

diff --git a/Changes b/Changes
index 64b01ef9959f4062952c876fa9801dda6f747142..767c01ae907f9c2326a37cff7c947cad7cae6618 100644 (file)
--- a/Changes
+++ b/Changes
@@ -8,6 +8,11 @@ Bug fixes:
  - fixes a regression introduced by the fixes for RT 11972
    http://rt.cpan.org/Ticket/Display.html?id=27546
 
+ - cropping outside the image would return an Imager object with
+   no low-level image object, instead of returning false.
+   Fixed by: Philip Gwyn (Leolo)
+   http://rt.cpan.org/Ticket/Display.html?id=27509
+
 Imager 0.58 - 16 May 2007
 ===========
 
index a4e3e07013f032f21f5db90a8fbb29eeec198784..5a3412e987a54748547365e1de509de89e09e71e 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -754,7 +754,10 @@ sub crop {
     $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);
index 3f2728d1fa2b29fd600ef5d8f70a57ed21d90b34..5b98a13550d3fa944a83aea03a6eb48338e0f698 100644 (file)
@@ -1,6 +1,6 @@
 #!perl -w
 use strict;
-use Test::More tests => 60;
+use Test::More tests => 64;
 require "t/testtools.pl";
 use Imager;
 
@@ -170,3 +170,13 @@ SKIP:
   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");
+}