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