File: PNG.pm

package info (click to toggle)
libimager-perl 1.019%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,824 kB
  • sloc: perl: 32,886; ansic: 28,193; makefile: 52; cpp: 4
file content (114 lines) | stat: -rw-r--r-- 1,995 bytes parent folder | download
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
package Imager::File::PNG;
use 5.006;
use strict;
use Imager;

BEGIN {
  our $VERSION = "0.99";

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

sub read {
  my ($class, $im, $io, %hsh) = @_;

  my $flags = 0;
  $hsh{png_ignore_benign_errors}
    and $flags |= IMPNG_READ_IGNORE_BENIGN_ERRORS;
  $im->{IMG} = i_readpng_wiol($io, $flags);

  unless ($im->{IMG}) {
    $im->_set_error(Imager->_error_as_msg);
    return;
  }
  return $im;
}

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

sub write {
  my ($class, $im, $io, %hsh) = @_;

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

  unless (i_writepng_wiol($im->{IMG}, $io)) {
    $im->_set_error(Imager->_error_as_msg);
    return;
  }
  return $im;
}

Imager->register_writer
  (
   type=>'png',
   single =>
   sub {
     my ($im, $io, %hsh) = @_;
     return __PACKAGE__->write($im, $io, %hsh);
   },
  );

__END__

=head1 NAME

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

=head1 SYNOPSIS

  use Imager;

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

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

=head1 DESCRIPTION

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

=head1 METHODS

Two low level class methods are provided, most for use by
L<Imager::File::APNG>, but it may later be used for other formats that
can encapsulate PNG such as ICO.

=over

=item C<< Imager::File::PNG->read($im, $io, %hsh) >>

Read a PNG image from the supplied L<Imager::IO> object C<$io> into
the L<Imager> object C<$im>.

Returns a true value on success.

=item C<< Imager::File::PNG->write($im, $io, %hsh) >>

Write a PNG image to the supplied L<Imager::IO> object C<$io> from the
L<Imager> object C<$im>.

Returns a true value on success.

=back

=head1 AUTHOR

Tony Cook <tonyc@cpan.org>

=head1 SEE ALSO

L<Imager>, L<Imager::Files>.

=cut