Debian Codegraph @

PNG/PNG.pm

raw
1 package Imager::File::PNG;
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::PNG', $VERSION);
11 }
12
13 sub read {
14 my ($class, $im, $io, %hsh) = @_;
15
16 my $flags = 0;
17 $hsh{png_ignore_benign_errors}
18 and $flags |= IMPNG_READ_IGNORE_BENIGN_ERRORS;
19 $im->{IMG} = i_readpng_wiol($io, $flags);
20
21 unless ($im->{IMG}) {
22 $im->_set_error(Imager->_error_as_msg);
23 return;
24 }
25 return $im;
26 }
27
28 Imager->register_reader
29 (
30 type=>'png',
31 single =>
32 sub {
33 my ($im, $io, %hsh) = @_;
34 __PACKAGE__->read($im, $io, %hsh);
35 },
36 );
37
38 sub write {
39 my ($class, $im, $io, %hsh) = @_;
40
41 $im->_set_opts(\%hsh, "i_", $im);
42 $im->_set_opts(\%hsh, "png_", $im);
43
44 unless (i_writepng_wiol($im->{IMG}, $io)) {
45 $im->_set_error(Imager->_error_as_msg);
46 return;
47 }
48 return $im;
49 }
50
51 Imager->register_writer
52 (
53 type=>'png',
54 single =>
55 sub {
56 my ($im, $io, %hsh) = @_;
57 return __PACKAGE__->write($im, $io, %hsh);
58 },
59 );
60
61 __END__
62
63 =head1 NAME
64
65 Imager::File::PNG - read and write PNG files
66
67 =head1 SYNOPSIS
68
69 use Imager;
70
71 my $img = Imager->new;
72 $img->read(file=>"foo.png")
73 or die $img->errstr;
74
75 $img->write(file => "foo.png")
76 or die $img->errstr;
77
78 =head1 DESCRIPTION
79
80 Imager's PNG support is documented in L<Imager::Files>.
81
82 =head1 METHODS
83
84 Two low level class methods are provided, most for use by
85 L<Imager::File::APNG>, but it may later be used for other formats that
86 can encapsulate PNG such as ICO.
87
88 =over
89
90 =item C<< Imager::File::PNG->read($im, $io, %hsh) >>
91
92 Read a PNG image from the supplied L<Imager::IO> object C<$io> into
93 the L<Imager> object C<$im>.
94
95 Returns a true value on success.
96
97 =item C<< Imager::File::PNG->write($im, $io, %hsh) >>
98
99 Write a PNG image to the supplied L<Imager::IO> object C<$io> from the
100 L<Imager> object C<$im>.
101
102 Returns a true value on success.
103
104 =back
105
106 =head1 AUTHOR
107
108 Tony Cook <[email protected]>
109
110 =head1 SEE ALSO
111
112 L<Imager>, L<Imager::Files>.
113
114 =cut