Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 122 lines (95 sloc) 2.197 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
package Imager::File::GIF;
use strict;
use Imager;
use vars qw($VERSION @ISA);

BEGIN {
  $VERSION = "0.89";

  require XSLoader;
  XSLoader::load('Imager::File::GIF', $VERSION);
}

Imager->register_reader
  (
   type=>'gif',
   single =>
   sub {
     my ($im, $io, %hsh) = @_;

     if ($hsh{gif_consolidate}) {
       if ($hsh{colors}) {
my $colors;
($im->{IMG}, $colors) =i_readgif_wiol( $io );
if ($colors) {
${ $hsh{colors} } = [ map { NC(@$_) } @$colors ];
}
       }
       else {
$im->{IMG} =i_readgif_wiol( $io );
       }
     }
     else {
       my $page = $hsh{page};
       defined $page or $page = 0;
       $im->{IMG} = i_readgif_single_wiol($io, $page);

       unless ($im->{IMG}) {
$im->_set_error(Imager->_error_as_msg);
return;
       }
       if ($hsh{colors}) {
${ $hsh{colors} } = [ $im->getcolors ];
       }
       return $im;
     }
   },
   multiple =>
   sub {
     my ($io, %hsh) = @_;

     my @imgs = i_readgif_multi_wiol($io);
     unless (@imgs) {
       Imager->_set_error(Imager->_error_as_msg);
       return;
     }

     return map bless({ IMG => $_, ERRSTR => undef }, "Imager"), @imgs;
   },
  );

Imager->register_writer
  (
   type=>'gif',
   single =>
   sub {
     my ($im, $io, %hsh) = @_;

     $im->_set_opts(\%hsh, "i_", $im);
     $im->_set_opts(\%hsh, "gif_", $im);

     unless (i_writegif_wiol($io, \%hsh, $im->{IMG})) {
       $im->_set_error(Imager->_error_as_msg);
       return;
     }
     return $im;
   },
   multiple =>
   sub {
     my ($class, $io, $opts, @ims) = @_;

     Imager->_set_opts($opts, "gif_", @ims);

     my @work = map $_->{IMG}, @ims;
     unless (i_writegif_wiol($io, $opts, @work)) {
       Imager->_set_error(Imager->_error_as_msg);
       return;
     }

     return 1;
   },
  );

__END__

=head1 NAME

Imager::File::GIF - read and write GIF files

=head1 SYNOPSIS

use Imager;

my $img = Imager->new;
$img->read(file=>"foo.gif")
or die $img->errstr;

$img->write(file => "foo.gif")
or die $img->errstr;

=head1 DESCRIPTION

Imager's GIF support is documented in L<Imager::Files>.

=head1 AUTHOR

Tony Cook <tonyc@cpan.org>

=head1 SEE ALSO

Imager, Imager::Files.

=cut
Something went wrong with that request. Please try again.