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}); }
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