]> git.imager.perl.org - imager.git/blobdiff - Imager.pm
difference() method
[imager.git] / Imager.pm
index 0a4c9a28a0e44af7c62faa1e4744a4f9f8bfad2c..41d687f08fc60d0bdfb6e57c4580dc91a2b3417a 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -147,7 +147,7 @@ BEGIN {
   require Exporter;
   require DynaLoader;
 
-  $VERSION = '0.39';
+  $VERSION = '0.40pre1';
   @ISA = qw(Exporter DynaLoader);
   bootstrap Imager $VERSION;
 }
@@ -396,6 +396,9 @@ sub init {
 #      i_init_fonts();
 #      $fontstate='ok';
 #    }
+  if (exists $parms{'t1log'}) {
+    i_init_fonts($parms{'t1log'});
+  }
 }
 
 END {
@@ -2196,7 +2199,7 @@ sub setpixel {
     or return undef;
   if (ref $x && ref $y) {
     unless (@$x == @$y) {
-      $self->{ERRSTR} = 'length of x and y mistmatch';
+      $self->{ERRSTR} = 'length of x and y mismatch';
       return undef;
     }
     if ($color->isa('Imager::Color')) {
@@ -2225,7 +2228,7 @@ sub setpixel {
 sub getpixel {
   my $self = shift;
 
-  my %opts = ( type=>'8bit', @_);
+  my %opts = ( "type"=>'8bit', @_);
 
   unless (exists $opts{'x'} && exists $opts{'y'}) {
     $self->{ERRSTR} = 'missing x and y parameters';
@@ -2240,7 +2243,7 @@ sub getpixel {
       return undef;
     }
     my @result;
-    if ($opts{type} eq '8bit') {
+    if ($opts{"type"} eq '8bit') {
       for my $i (0..$#{$opts{'x'}}) {
         push(@result, i_get_pixel($self->{IMG}, $x->[$i], $y->[$i]));
       }
@@ -2253,7 +2256,7 @@ sub getpixel {
     return wantarray ? @result : \@result;
   }
   else {
-    if ($opts{type} eq '8bit') {
+    if ($opts{"type"} eq '8bit') {
       return i_get_pixel($self->{IMG}, $x, $y);
     }
     else {
@@ -2399,6 +2402,27 @@ sub map {
   return $self;
 }
 
+sub difference {
+  my ($self, %opts) = @_;
+
+  defined $opts{mindist} or $opts{mindist} = 0;
+
+  defined $opts{other}
+    or return $self->_set_error("No 'other' parameter supplied");
+  defined $opts{other}{IMG}
+    or return $self->_set_error("No image data in 'other' image");
+
+  $self->{IMG}
+    or return $self->_set_error("No image data");
+
+  my $result = Imager->new;
+  $result->{IMG} = i_diff_image($self->{IMG}, $opts{other}{IMG}, 
+                                $opts{mindist})
+    or return $self->_set_error($self->_error_as_msg());
+
+  return $result;
+}
+
 # destructive border - image is shrunk by one pixel all around
 
 sub border {
@@ -2513,6 +2537,7 @@ sub _set_error {
   else {
     $ERRSTR = $msg;
   }
+  return;
 }
 
 # Default guess for the type of an image from extension
@@ -2727,15 +2752,13 @@ Helper for making gradient profiles.
 
 =head2 Basic Overview
 
-An Image object is created with C<$img = Imager-E<gt>new()> Should
-this fail for some reason an explanation can be found in
-C<$Imager::ERRSTR> usually error messages are stored in
-C<$img-E<gt>{ERRSTR}>, but since no object is created this is the only
-way to give back errors.  C<$Imager::ERRSTR> is also used to report
-all errors not directly associated with an image object. Examples:
+An Image object is created with C<$img = Imager-E<gt>new()>.
+Examples:
 
-  $img=Imager->new(); # This is an empty image (size is 0 by 0)
-  $img->open(file=>'lena.png',type=>'png'); # initializes from file
+  $img=Imager->new();                         # create empty image
+  $img->open(file=>'lena.png',type=>'png') or # read image from file
+     die $img->errstr();                      # give an explanation
+                                              # if something failed
 
 or if you want to create an empty image:
 
@@ -2744,6 +2767,14 @@ or if you want to create an empty image:
 This example creates a completely black image of width 400 and height
 300 and 4 channels.
 
+When an operation fails which can be directly associated with an image
+the error message is stored can be retrieved with
+C<$img-E<gt>errstr()>.
+
+In cases where no image object is associated with an operation
+C<$Imager::ERRSTR> is used to report errors not directly associated
+with an image object.
+
 =head1 SUPPORT
 
 You can ask for help, report bugs or express your undying love for
@@ -2756,6 +2787,7 @@ To subscribe send a message with C<subscribe> in the body to:
 or use the form at:
 
    http://www.molar.is/en/lists/imager-devel/
+   (annonymous is temporarily off due to spam)
 
 where you can also find the mailing list archive.
 
@@ -2769,14 +2801,21 @@ Bugs are listed individually for relevant pod pages.
 
 =head1 AUTHOR
 
-Arnar M. Hrafnkelsson (addi@umich.edu) and Tony Cook
+Arnar M. Hrafnkelsson (addi@imager.perl.org) and Tony Cook
 (tony@imager.perl.org) See the README for a complete list.
 
 =head1 SEE ALSO
 
-perl(1), Imager::Color(3), Imager::Font(3), Imager::Matrix2d(3),
+perl(1), Imager::ImageTypes(3), Imager::Files(3), Imager::Draw(3),
+Imager::Color(3), Imager::Fill(3), Imager::Font(3),
+Imager::Transformations(3), Imager::Engines(3), Imager::Filters(3),
+Imager::Expr(3), Imager::Matrix2d(3), Imager::Fountain(3)
 
 Affix::Infix2Postfix(3), Parse::RecDescent(3)
 http://www.eecs.umich.edu/~addi/perl/Imager/
 
 =cut
+
+
+
+