move the GIF file handling code into a sub-module
[imager.git] / GIF / GIF.pm
CommitLineData
ec6d8908
TC
1package Imager::File::GIF;
2use strict;
3use Imager;
4use vars qw($VERSION @ISA);
5
6BEGIN {
7 $VERSION = "0.77";
8
9 eval {
10 require XSLoader;
11 XSLoader::load('Imager::File::GIF', $VERSION);
12 1;
13 } or do {
14print STDERR "Falling back to DynaLoader ($@)\n";
15 require DynaLoader;
16 push @ISA, 'DynaLoader';
17 bootstrap Imager::File::GIF $VERSION;
18 };
19}
20
21Imager->register_reader
22 (
23 type=>'gif',
24 single =>
25 sub {
26 my ($im, $io, %hsh) = @_;
27
28 if ($hsh{gif_consolidate}) {
29 if ($hsh{colors}) {
30 my $colors;
31 ($im->{IMG}, $colors) =i_readgif_wiol( $io );
32 if ($colors) {
33 ${ $hsh{colors} } = [ map { NC(@$_) } @$colors ];
34 }
35 }
36 else {
37 $im->{IMG} =i_readgif_wiol( $io );
38 }
39 }
40 else {
41 my $page = $hsh{page};
42 defined $page or $page = 0;
43 $im->{IMG} = i_readgif_single_wiol($io, $page);
44
45 unless ($im->{IMG}) {
46 $im->_set_error(Imager->_error_as_msg);
47 return;
48 }
49 if ($hsh{colors}) {
50 ${ $hsh{colors} } = [ $im->getcolors ];
51 }
52 return $im;
53 }
54 },
55 multiple =>
56 sub {
57 my ($io, %hsh) = @_;
58
59 my @imgs = i_readgif_multi_wiol($io);
60 unless (@imgs) {
61 Imager->_set_error(Imager->_error_as_msg);
62 return;
63 }
64
65 return map bless({ IMG => $_, ERRSTR => undef }, "Imager"), @imgs;
66 },
67 );
68
69Imager->register_writer
70 (
71 type=>'gif',
72 single =>
73 sub {
74 my ($im, $io, %hsh) = @_;
75
76 $im->_set_opts(\%hsh, "i_", $im);
77 $im->_set_opts(\%hsh, "gif_", $im);
78
79 unless (i_writegif_wiol($io, \%hsh, $im->{IMG})) {
80 $im->_set_error(Imager->_error_as_msg);
81 return;
82 }
83 return $im;
84 },
85 multiple =>
86 sub {
87 my ($class, $io, $opts, @ims) = @_;
88
89 Imager->_set_opts($opts, "gif_", @ims);
90
91 my @work = map $_->{IMG}, @ims;
92 unless (i_writegif_wiol($io, $opts, @work)) {
93 Imager->_set_error(Imager->_error_as_msg);
94 return;
95 }
96
97 return 1;
98 },
99 );
100
101__END__
102
103=head1 NAME
104
105Imager::File::GIF - read and write GIF files
106
107=head1 SYNOPSIS
108
109 use Imager;
110
111 my $img = Imager->new;
112 $img->read(file=>"foo.gif")
113 or die $img->errstr;
114
115 $img->write(file => "foo.gif")
116 or die $img->errstr;
117
118=head1 DESCRIPTION
119
120Imager's GIF support is documented in L<Imager::Files>.
121
122=head1 AUTHOR
123
124Tony Cook <tony@imager.perl.org>
125
126=head1 SEE ALSO
127
128Imager, Imager::Files.
129
130=cut