]> git.imager.perl.org - imager.git/blobdiff - Imager.pm
discussion from IRC of some interfaces/features
[imager.git] / Imager.pm
index 721460cc92a4b95c092d11efd3167dc3dfd32966..38f7d152645b9c86c731afaa9ae02adc5c420f96 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -493,9 +493,35 @@ sub read {
   if ($input{fd}) { $fd=$input{fd} };
 
   if ( $input{type} eq 'gif' ) {
-    if (exists $input{data}) { $self->{IMG}=i_readgif_scalar($input{data}); }
-    else { $self->{IMG}=i_readgif( $fd ) }
-    if ( !defined($self->{IMG}) ) { $self->{ERRSTR}= 'reading GIF:'._error_as_msg(); return undef; }
+    my $colors;
+    if ($input{colors} && !ref($input{colors})) {
+      # must be a reference to a scalar that accepts the colour map
+      $self->{ERRSTR} = "option 'colors' must be a scalar reference";
+      return undef;
+    }
+    if (exists $input{data}) {
+      if ($input{colors}) {
+       ($self->{IMG}, $colors) = i_readgif_scalar($input{data});
+      }
+      else {
+       $self->{IMG}=i_readgif_scalar($input{data});
+      }
+    }
+    else { 
+      if ($input{colors}) {
+       ($self->{IMG}, $colors) = i_readgif( $fd );
+      }
+      else {
+       $self->{IMG} = i_readgif( $fd )
+      }
+    }
+    if ($colors) {
+      # we may or may not change i_readgif to return blessed objects...
+      ${$input{colors}} = [ map { NC(@$_) } @$colors ];
+    }
+    if ( !defined($self->{IMG}) ) {
+      $self->{ERRSTR}= 'reading GIF:'._error_as_msg(); return undef;
+    }
     $self->{DEBUG} && print "loading a gif file\n";
   } elsif ( $input{type} eq 'jpeg' ) {
     if (exists $input{data}) { ($self->{IMG},$self->{IPTCRAW})=i_readjpeg_scalar($input{data}); }
@@ -1477,6 +1503,11 @@ The second example shows how to read an image from a scalar, this is
 usefull if your data originates from somewhere else than a filesystem
 such as a database over a DBI connection.
 
+If you are reading from a gif image file, you can supply a 'colors'
+parameter which must be a reference to a scalar.  The referenced
+scalar will receive an array reference which contains the colors, each
+represented as an Imager::Color object.
+
 If you already have an open file handle, for example a socket or a
 pipe, you can specify the 'fd' parameter instead of supplying a
 filename.  Please be aware that you need to use fileno() to retrieve