=pod =encoding UTF-8 =head1 NAME Image::PNG::Libpng - Perl interface to the C library "libpng". =head1 SYNOPSIS Libpng-like interface: use Image::PNG::Libpng ':all'; my $png = create_read_struct (); open my $file, '<:raw', 'nice.png' or die $!; $png->init_io ($file); $png->read_png (); close $file; # Get all valid chunks my $valid = $png->get_valid (); my @valid_chunks = sort grep {$valid->{$_}} keys %$valid; print "Valid chunks are ", join (", ", @valid_chunks), "\n"; # Print image information my $header = $png->get_IHDR (); for my $k (keys %$header) { print "$k: $header->{$k}\n"; } (This example is included as L|https://fastapi.metacpan.org/source/BKB/Image-PNG-Libpng-0.60/examples/synopsis.pl> in the distribution.) Simple interface: use Image::PNG::Libpng ':all'; my $png = read_png_file ('../t/tantei-san.png'); # Get all valid chunks my $valid = $png->get_valid (); my @valid_chunks = sort grep {$valid->{$_}} keys %$valid; print "Valid chunks are ", join (", ", @valid_chunks), "\n"; # Print image information my $header = $png->get_IHDR (); for my $k (keys %$header) { if ($k eq 'color_type') { print "$k: " . color_type_name ($header->{$k}) . "\n"; } else { print "$k: $header->{$k}\n"; } } my $wpng = $png->copy_png (); $wpng->write_png_file ('new.png'); (This example is included as L|https://fastapi.metacpan.org/source/BKB/Image-PNG-Libpng-0.60/examples/synopsis-easy.pl> in the distribution.) =head1 VERSION This document describes Image::PNG::Libpng version 0.60, corresponding to git commit L at Tue Mar 17 11:06:31 2026 +0900. Unless otherwise qualified, comments in this document on the libpng source code and documentation refer to libpng version 1.6.45. Libpng is not bundled with this distribution, so your installed version may vary. =head1 DESCRIPTION Image::PNG::Libpng is a Perl library for accessing the contents of PNG (Portable Network Graphics) images. Image::PNG::Libpng enables Perl to use the "libpng" library to read and write files in PNG format. Image::PNG::Libpng does not contain the libpng library. The libpng library must be installed on your computer prior to installing Image::PNG::Libpng. Image::PNG::Libpng consists of Perl subroutines which mirror the C functions in libpng, plus helper subroutines to make it easier to read and write PNG data in Perl. For those familiar with libpng, the section L explains the differences with libpng. =head1 FUNCTIONS The functions in the module are gathered into the following categories: L, which describes some convenience functions, L, which describes functions which closely mirror libpng, L, which describes functions for reading and writing the meta-information about PNG images, L, which describes functions for accessing the image data itself, L, L, L, L, L, L, L, functions from libpng which don't fit elsewhere, and L, which are functions specific to this module. =head1 Simple input and output These convenience functions combine common operations. They are not part of the original libpng API. =head2 copy_png my $outpng = $png->copy_png (); Copy a PNG from a read to a write structure. This function bridges two kinds of object, "read a png" objects created by L and "write a png" objects created by L. This function copies all the valid chunks from a read structure to a write structure. The following example demonstrates copying a PNG. use utf8; use FindBin '$Bin'; use Image::PNG::Libpng qw(read_png_file write_png_file) ; my $pngin = read_png_file ("$Bin/../t/tantei-san.png"); my $pngout = $pngin->copy_png (); $pngout->set_text ([{key => 'Name', text => 'Shunsaku Kudo'}]); # $pngout->write_png_file ('copy.png'); (This example is included as L|https://fastapi.metacpan.org/source/BKB/Image-PNG-Libpng-0.60/examples/copy-png.pl> in the distribution.) =head2 create_reader my $png = create_reader ('file.png'); $png->read_png (); This combines L, C, and L on the specified file name but does not read the file in. This is for the case that the user wants to apply some kind of transformation. =head3 Setting the background In the following example, the user sets the background with L to replace the alpha channel. use utf8; use FindBin '$Bin'; use Image::PNG::Libpng ':all'; use Image::PNG::Const ':all'; my $file = "$Bin/luv.png"; my %color = (red => 0xC0, green => 0xFF, blue => 0xFF); my $png = create_reader ($file); $png->set_background (\%color, PNG_BACKGROUND_GAMMA_SCREEN, 0); $png->read_png (); my $wpng = copy_png ($png); $wpng->write_png_file ("$Bin/set-background.png"); (This example is included as L|https://fastapi.metacpan.org/source/BKB/Image-PNG-Libpng-0.60/examples/set-background.pl> in the distribution.) L is included in the distribution. =begin html

The input image has a transparent background:

examples/luv.png
=end html L is included in the distribution. =begin html

The output image has a blue background:

examples/set-background.png
=end html This function was added to the module in version 0.53. =head2 create_writer my $png = create_writer ('file.png'); $png->set_IHDR (\%ihdr); $png->set_rows (\@rows); $png->write_png (); This combines L, C, and L on the specified file name but does not read the file in. This is for the case that the user wants to apply some kind of transformation before writing. This function was added to the module in version 0.53. =head2 read_from_scalar my $png = read_from_scalar ($string); This creates an image structure C<$png> from the contents of a Perl scalar variable C<$string> containing PNG image data, for example data read from a file, or data obtained from a web page. The first argument, C<$png>, is a PNG structure created with L. It reads in all the data from the structure on being called. This is useful when image data is stored in a Perl scalar. For example use Image::PNG::Libpng 'read_from_scalar'; use LWP::Simple; use JSON::Create; my $image_data = get 'http://libpng.org/pub/png/img_png/libpng-88x31.png'; # Now $image_data contains the PNG file my $png = read_from_scalar ($image_data); # Now $png contains the PNG information from the image. # Get the header. my $header = $png->get_IHDR (); my $jc = JSON::Create->new (indent => 1, sort => 1); print $jc->run ($header); (This example is included as L|https://fastapi.metacpan.org/source/BKB/Image-PNG-Libpng-0.60/examples/get-www-png.pl> in the distribution.) The output looks like this: { "bit_depth":4, "color_type":3, "height":31, "interlace_method":0, "width":88 } See also L. =head2 read_png_file my $png = read_png_file ('q.png'); Open F and read its contents into C<$png>. This combines L, C, L, and L. The return value is the same as that of L with the entire PNG image already read in. The optional argument to L can be specified using an optional C argument: my $png = read_png_file ('file.png', transforms => PNG_TRANSFORM_EXPAND); L is used to signal errors opening or closing the file. =head2 set_transforms $png->set_transforms (PNG_TRANSFORM_BGR); Set transforms for reading and writing. This is the same as the optional argument to L or L. If both this and the optional argument are given, the optional argument overrides what is set here. =head2 write_png_file $png->write_png_file ('nice.png'); This combines open, L, and L to write an entire PNG image out to the file name specified by the argument. C<$png> must be the object created by L, so L followed by a call to this does not work. See L if you need to do that kind of operation. The optional argument to L can be specified using L. L is used to signal errors opening or closing the file. =head2 write_to_scalar my $image_data = $png->write_to_scalar (); This writes the PNG image data in C<$png> into a Perl scalar. The first argument, C<$png>, is a writeable PNG structure created with L. The return value of the subroutine is the Perl scalar containing the image data. So, for example, # This CGI script prints a PNG in a random colour. use Image::PNG::Libpng ':all'; use Image::PNG::Const ':all'; my $png = create_write_struct (); my $size = 100; $png->set_IHDR ({height => $size, width => $size, bit_depth => 8, color_type => PNG_COLOR_TYPE_RGB}); my $bytes = pack "CCC", randcol (), randcol (), randcol (); my @rows = ($bytes x $size) x $size; $png->set_rows (\@rows); my $img = $png->write_to_scalar (); binmode STDOUT; print "Content-Type:image/png\r\n\r\n$img"; exit; sub randcol { return int (rand () * 0x100); } (This example is included as L|https://fastapi.metacpan.org/source/BKB/Image-PNG-Libpng-0.60/examples/png-cgi.pl> in the distribution.) See also L. The optional argument to L can be specified using L. =head1 Libpng-style input and output There are two different "new"-like functions, depending on whether you want to read or write a PNG, L and L. These are based on the libpng API. Input uses C plus L followed by L or L. =head2 Examples =head3 A self-pixellating program This example demonstrates writing a monochrome PNG by creating a write structure with L, opening a filehandle to write it, associating the filehandle with the PNG structure with L, then using the functions L, L, and then L to actually write the PNG data to the file. use utf8; use FindBin '$Bin'; use Image::PNG::Libpng ':all'; use Image::PNG::Const ':all'; my $outfile = "$Bin/mono.png"; my ($height, $width, $rows) = pixelate (__FILE__, 5); my $png = create_write_struct (); open my $out, ">:raw", $outfile or die $!; $png->init_io ($out); $png->set_IHDR ({height => $height, width => $width, bit_depth => 1, color_type => PNG_COLOR_TYPE_GRAY}); $png->set_text ([{key => 'silly', text => 'finely-tuned breakfast cereal',}]); $png->set_tIME ({year => 1999}); $png->write_info (); $png->set_invert_mono (); # PNG puts the leftmost pixel in the high-order part of the byte. $png->set_packswap (); $png->write_image ($rows); $png->write_end (); close $out or die $!; exit; sub pixelate { my ($file, $box) = @_; open my $in, "<", $file or die "Can't open '$file': $!"; my $width = 0; my @lines; while (<$in>) { chomp; s/\t/ /g; push @lines, $_; if (length ($_) > $width) { $width = length ($_); } } close $in or die $!; $width *= $box; my $height = scalar (@lines) * $box; my $zero = pack "C", 0; my $bwidth = int(($width+7)/8); my @rows = ($zero x $bwidth) x $height; for my $r (0..$height-1) { my $y = int ($r/$box); my $line = $lines[$y]; for my $x (0..length ($line) - 1) { if (substr ($line, $x, 1) ne ' ') { for my $c (0..$box - 1) { my $offset = $x*$box + $c; my $byte = int ($offset / 8); my $bit = $offset % 8; my $octet = ord (substr ($rows[$r], $byte, 1)); substr ($rows[$r], $byte, 1) = chr ($octet | 1<<$bit); } } } } return ($height, $width, \@rows); } (This example is included as L|https://fastapi.metacpan.org/source/BKB/Image-PNG-Libpng-0.60/examples/libpng-write.pl> in the distribution.) L is included in the distribution. =begin html

The output has a bit depth of 1:

examples/mono.png
=end html =head2 create_read_struct my $png = create_read_struct (); Create a structure for reading a PNG. The return value can be used as an object with the other functions as methods. It can be copied to a write structure with L. This function corresponds to C in libpng plus C (see L) with the error and warning handler variables set up to use Perl's error reporting. =head2 create_write_struct my $png = create_write_struct (); Create a structure for writing a PNG. This can be used as an object with the other functions as methods. This function corresponds to C in libpng plus C (see L) with the error and warning handler variables set up to use Perl's error reporting. =head2 init_io open my $file, "<", 'nice.png'; $png->init_io ($file); Set the file which C<$png> reads or writes to C<$file>. C<$file> must be an already-opened Perl file handle. If C<$png> was created with L, C<$file> must be opened for writing. If C<$png> was created with L, C<$file> must be open for reading. Since PNG files are binary files, it is safest to specify the "raw" pragma or use "binmode" with the file to override any default text file encoding which Perl might be using: open my $file, ">:raw", 'output.png'; or open my $file, ">", 'output.png'; binmode $file; This function corresponds to C in libpng, with a Perl file handle substituting for the C C. =head3 Caveats when using init_io =head4 Check the return value of open On some versions of Perl, L may crash in some circumstances with an error like "segmentation fault", if you use code like my $png = create_read_struct (); open my $file, "<:raw", "some.png"; $png->init_io ($file); and you do not check whether the call to C was successful, and F does not exist. The crash occurs within Perl's conversion of C<$file> into a C C pointer, before this module's code runs. This bug was fixed in Perls after version 5.24.1. To avoid trouble, please check the return value of C. =head4 Cannot deal with non-file filehandles Since C is a Perl access to an underlying C function C, it requires something which can be passed to the underlying C as a C, C's file structure. If, for example you use L or open a scalar reference as a file handle, since these actions do not create a C file structure, an error of the form C will occur. If you have a PNG in the form of a Perl scalar, use L instead of C, which uses a C function called C so that the C library can access the data in the Perl scalar. See also L. =head2 read_end $png->read_end (); Read the part of the PNG file after the image data. This function corresponds to C in libpng. =head2 read_image my $rows = $png->read_image (); Read the image data of the PNG file. This function corresponds to C in libpng. =head2 read_info $png->read_info (); Read the part of the PNG file before the image data. This function corresponds to C in libpng. =head2 read_png $png->read_png (); Read the entire PNG file into memory. You can provide an argument containing transformations to apply to the image: use Image::PNG::Const qw/PNG_TRANSFORM_STRIP_ALPHA/; $png->read_png (PNG_TRANSFORM_STRIP_ALPHA); If the argument is omitted, the default value of C (the "do nothing" value) is applied. The possible transformations which can be applied are =over =item PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA to BGRA. See also L. =item PNG_TRANSFORM_EXPAND Perform set_expand(). See also L. =item PNG_TRANSFORM_EXPAND_16 Expand samples to 16 bits. See also L. =item PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples to RGB (or GA to RGBA). See also L. =item PNG_TRANSFORM_IDENTITY No transformation. =item PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity to transparency. See also L. =item PNG_TRANSFORM_INVERT_MONO Invert monochrome images. See also L. =item PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit samples to bytes. See also L. =item PNG_TRANSFORM_PACKSWAP Change order of packed pixels to LSB first. See also L. =item PNG_TRANSFORM_SCALE_16 Strip 16-bit samples to 8-bit accurately. See also L. =item PNG_TRANSFORM_SHIFT Normalize pixels to the sBIT depth. =item PNG_TRANSFORM_STRIP_16 Chop 16-bit samples to 8-bit less accurately. See also L. =item PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel. =item PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA to AG. See also L. =item PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples. See also L. =back This function corresponds to C in libpng with a default value for the third argument. The fourth, unused, argument to C does not need to be supplied. See L. It does not take a second "info" argument. See L. =head2 read_update_info $png->read_update_info (); ⛐πŸ€ͺ⚠ Inside Image::PNG::Libpng, the libpng function C is called before reading image data. According to L, this function may only be called once for any particular info structure. So although the above Perl interface exists in the module, it is strongly recommended to not use this unless you know exactly what you are doing, since it will usually cause an error when the image data is read. This function corresponds to C in libpng =head2 write_end $png->write_end (); Write the final part of the PNG file. This function corresponds to C in libpng. =head2 write_image $png->write_image ($rows); Write the image of the PNG file. C<$rows> is an array reference as per L. This function corresponds to C in libpng. =head2 write_info $png->write_info (); Write the first part of the PNG file. This function corresponds to C in libpng. =head2 write_png $png->write_png (); This writes the PNG to the file stream which was associated with it using L. For example, open my $output, ">:raw", 'out.png'; $png->init_io ($output); $png->write_png (); close $output; An optional argument consists of transformations to apply to the PNG image before writing it: use Image::PNG::Const qw/PNG_TRANSFORM_STRIP_ALPHA/; $png->write_png (PNG_TRANSFORM_STRIP_ALPHA); The transformations which can be applied are as follows: =over =item PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA to BGRA. See also L. =item PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity to transparency. See also L. =item PNG_TRANSFORM_INVERT_MONO Invert monochrome images. See also L. =item PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit samples to bytes. See also L. =item PNG_TRANSFORM_PACKSWAP Change order of packed pixels to LSB first. See also L. =item PNG_TRANSFORM_SHIFT Normalize pixels to the sBIT depth. =item PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing filler bytes. =item PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading filler bytes. =item PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA to AG. See also L. =item PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples. See also L. =back This function corresponds to C in libpng. =head1 The image header These functions handle the header part of PNG image data. See L of L for information on the PNG standards for the image header. =head2 color_type_name $name = color_type_name ($color_type); This is a convenience function which returns a string corresponding to the numerical color type in C<$color_type>. The name is in upper case, with words separated by underscores, as in C. use Image::PNG::Libpng ':all'; my $png = read_png_file ('tantei-san.png'); my $name = color_type_name ($png->get_IHDR->{color_type}); print "Your PNG has colour type $name.\n"; (This example is included as L|https://fastapi.metacpan.org/source/BKB/Image-PNG-Libpng-0.60/examples/color-type-name.pl> in the distribution.) This function does not correspond to anything in libpng. The names of the color types are taken from those defined in the libpng header file, C. =head2 get_bit_depth my $bit_depth = $png->get_bit_depth (); Get the bit depth, the number of bits for one channel of one pixel. This function corresponds to C in libpng =head2 get_channels my $channels = $png->get_channels (); Get the number of channels, from one to four. The channels are the components of pixels, for example the red channel or the alpha (transparency) channel. The return value is 1 for color type C and C, 2 for C, 3 for C and 4 for C or C with a filler byte. Note that the number of channels does not necessarily correspond to the number of bytes, since the bit depth can also be 1, 2, 4, 8, or 16, depending on the color type. See also the convenience function L. This function corresponds to C in libpng =head2 get_color_type my $color_type = $png->get_color_type (); This returns an integer value. If you want to get a name for the color type, use L. This function corresponds to C in libpng. =head2 get_IHDR my $IHDR = $png->get_IHDR (); Read the IHDR information from the PNG file. The return value is a hash reference containing the following key/value pairs: =over =item width The width of the image in pixels. =item height The height of the image in pixels. =item bit_depth The bit depth of the image (the number of bits used for each color in a pixel). This can take the values 1, 2, 4, 8, 16. =item color_type The color type. This can take the values PNG_COLOR_TYPE_GRAY, PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, PNG_COLOR_TYPE_RGB_ALPHA. =item interlace_method The method of interlacing. This can take the values PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7. =back So, for example, to get the width and height of an image, my $ihdr = $png->get_IHDR (); printf "Your image is %d x %d\n", $ihdr->{width}, $ihdr->{height}; This function corresponds to C in libpng, with a single Perl hash reference used instead of the several pointers to integers used in libpng. It does not return the fields C and C, since these are always 0. See L. =head2 get_image_height my $height = $png->get_image_height (); Get the image's height from the header. This function corresponds to C in libpng =head2 get_image_width my $width = $png->get_image_width (); Get the image's width from the header. This function corresponds to C in libpng =head2 get_interlace_type my $interlace_type = $png->get_interlace_type (); Get the interlace type. This is either PNG_INTERLACE_NONE or PNG_INTERLACE_ADAM7. This function corresponds to C in libpng =head2 get_valid my $valid = $png->get_valid (); if ($valid->{oFFs}) { print "The PNG has valid screen offsets.\n"; } This function returns a hash with a key for each possible chunk which may or may not be valid. The chunks which you can test for are L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, L, and L. Whereas L tells you whether the installed libpng on your system supports various chunks, this tells you whether the chunks are present in a particular PNG image file. The first argument, C<$png>, is a PNG structure created with L. This function corresponds to C in libpng, with the difference being that the return value is a hash containing a key for each possible chunk. =head2 height my $height = $png->height (); Alias for L. This is not exported, it's intended for use with the object only. =head2 set_IHDR my $ihdr = {width => 10, height => 10, bit_depth => 8, color_type => PNG_COLOR_TYPE_RGB}; $png->set_IHDR ($ihdr); Set the IHDR chunk (the image header) of the PNG image. The first argument, C<$png>, is a writeable PNG structure created with L. The second argument is a hash with the following values: =over =item width The width of the image in pixels. This cannot be zero, negative, or omitted. =item height The height of the image in pixels. This cannot be zero, negative, or omitted. =item bit_depth The bit depth of the image (the number of bits used for each color in a pixel). This cannot be omitted. This can have the values 1, 2, 4, 8, 16. =item color_type The color type. This cannot be omitted. This can have the values PNG_COLOR_TYPE_GRAY, PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, PNG_COLOR_TYPE_RGB_ALPHA. =item interlace_method The method of interlacing. If this is omitted, it's set to PNG_INTERLACE_NONE. This can have the values PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7. =back Other fields in the hash are ignored. This function corresponds to C in libpng, with a single Perl hash reference used instead of the seven integers. The values C, C, may be supplied by the user but are ignored since they may only take the value 0. See L. =head2 sig_cmp if (sig_cmp ($should_be_png)) { print "Your data does not have a PNG signature.\n"; } This subroutine looks at C<$should_be_png> and checks whether its first bytes correspond to a valid PNG signature. It returns a true value if they do not. It can also take two further arguments consisting of a byte offset and a number of bytes to check respectively: sig_cmp ($should_be_png, 0, 8); If these arguments are not supplied, the byte offset is assumed to be zero, and the number of bytes to check is assumed to be eight. This function corresponds to C in libpng, with default arguments of 0 and 8 if second and third arguments are not supplied. =head2 width my $width = $png->width (); Alias for L. This is not exported, it's intended for use with the object only. =head1 Image data These functions deal with accessing the image data itself. =head2 get_rowbytes my $bytes_in_a_row = $png->get_rowbytes (); This returns the number of bytes needed to hold a transformed row of an image. This function corresponds to C in libpng. =head2 get_rows my $rows = $png->get_rows (); my $pixel = substr ($rows->[10], 20, 1); This returns the rows of the PNG image, after uncompressing and unfiltering, as binary data. The return value, C<$rows> in the example, is an array reference with a number of rows equal to the height of the PNG image. Each element of the array reference is a string containing the binary data making up a row of the image. The values of individual pixels can be extracted from using a function such as C or C. This binary data is likely to contain bytes equal to zero. L gives the number of bytes in each row. Each row is a Perl string. Perl terminates each row of data with an extra zero byte at the end. This function corresponds to C in libpng. =head2 set_rows $png->set_rows (\@rows); Set the rows of data to be written in to the PNG to C<@rows>. C<@rows> needs to contain at least the same number of rows of data as the height of the PNG image set with L, and the length of each entry needs to be at least the width of the image multiplied by the number of bytes required for each pixel. This function was changed to copy the data in version 0.46. This function corresponds to C in libpng. =head1 Text chunks See L of L for information on the PNG standards for text information. =head2 get_text my $text_chunks = $png->get_text (); This gets all of the text chunks in the PNG image and returns them as an array reference. Each element of the array represents one text chunk. This element is a hash reference with keys such as C, C, or C taken from the PNG's information. The text data is uncompressed by libpng. If it is international text (C), it is put into Perl's internal Unicode encoding if it is found to be valid UTF-8. (PNG "international text", C is required to be in the UTF-8 encoding, and non-international text is required to contain whitespace and printable ASCII characters only. See L for more on the requirements of a PNG text section.) This function corresponds to C in libpng, with a Perl array of hash references substituted for the C array of structs used by libpng. See L for details of the keys and values which may be returned. =head2 set_text $png->set_text ([\%chunk1, \%chunk2]); This sets the text chunks in a writeable image. The input value is an array reference containing one or more hash references. Each hash reference must have a C value for the text. According to the PNG specification, this should be between one and 79 bytes in length. This module enforces that restriction, so if you supply a key longer than that, the chunk cannot be added. A hash reference may also have the following: =over =item C The value of C controls the compression of the text. If C is not supplied, a default value of PNG_TEXT_COMPRESSION_NONE is applied. The C field can take the following values, available from L: =over =item PNG_TEXT_COMPRESSION_NONE TEXT = Printable ASCII and space characters. =item PNG_TEXT_COMPRESSION_zTXt TEXT = Printable ASCII and space characters. =item PNG_ITXT_COMPRESSION_NONE ITXT = International text, should be UTF-8. =item PNG_ITXT_COMPRESSION_zTXt ITXT = International text, should be UTF-8. =back =item C The string length of international text in bytes. ⛐πŸ€ͺ⚠ This is ignored by libpng when writing text chunks. When reading text chunks, if the text is marked as international text, libpng adds the length of the string in bytes in this field rather than in L. =item C This should be set to name of the language of the text, if the text chunk is iTXt. According to the PNG specification, "It is an ISO 646.IRV:1991 [ISO 646] string consisting of hyphen-separated words of 1-8 alphanumeric characters each (for example cn, en-uk, no-bok, x-klingon, x-KlInGoN)." Support for writing C was added in version 0.49 of this module. (Prior to that undocumented support existed via a differently-named key.) ⛐πŸ€ͺ⚠ This module does not attempt to check the supplied value, but merely passes it to libpng. libpng appears not to check the value either, nor to enforce restrictions on its length. =item C This corresponds to the "Translated keyword" of the PNG specification. Note that the user needs to supply C and L as well as C. Support for writing C was added in version 0.49 of this module. (Prior to that undocumented support existed via a differently-named key.) =item C The value of "text" is added to the PNG as the text segment. This can be omitted if you just want to write a key value without any accompanying text. =item C The string length in bytes. The user may set this, but it is ignored when writing PNG text chunks, instead this module uses the string length obtained from Perl. This key contains the length of the string when reading text chunks via L, but if the text is marked as international text, L is used to return its length in bytes, rather than this. =back Whether or not the value of C is an ITXT field is decided by the value of C. People who want to fiddle with the text compression applied can do so via L and the other functions described below that. If C is called more than once, the chunks are not overwritten but appended to the existing ones. (This behaviour is from libpng itself.) Prior to version 0.50, C would fail silently if the user added invalid chunks, for example hash references without a valid C, or things which were not hash references at all. From version 0.50, all invalid inputs cause fatal errors. However, unknown keys in the hash references do not cause fatal errors. This function corresponds to C in libpng. =head3 Example use utf8; use Image::PNG::Const ':all'; use Image::PNG::Libpng ':all'; my $png = create_write_struct (); $png->set_IHDR ({width => 1, height => 1, bit_depth => 8, color_type => PNG_COLOR_TYPE_GRAY}); $png->set_rows (['X']); $png->set_text ([{ compression => PNG_TEXT_COMPRESSION_NONE, key => "Copyright", text => "Copyright (C) 2020 Fat Cat", }, { compression => PNG_ITXT_COMPRESSION_zTXt, key => "Copyright", lang_key => '著者権', lang => 'ja_JP', text => 'Β©δ»€ε’ŒοΌ’εΉ΄θŒ‰θŽ‰γƒ‹γƒ£γƒ³γƒγƒΌγ‚¬γƒΌγ•γ‚“', }]); $png->write_png_file ('copyright.png'); (This example is included as L|https://fastapi.metacpan.org/source/BKB/Image-PNG-Libpng-0.60/examples/set-text.pl> in the distribution.) =head2 text_compression_name my $name = Image::PNG::Libpng::text_compression_name ($text->{compression}); Given a numerical text compression type, return the equivalent name. The name is in upper case. The possible return values are =over =item TEXT_NONE =item TEXT_zTXt =item ITXT_NONE =item ITXT_zTXt =item an empty string if the compression method is unknown. =back The compression field is also used to store the information about whether the text is "international text" in UTF-8 or not. This function does not correspond to anything in libpng. The names of the text compression types are based on those in C, but without the word "COMPRESSION", so for example the libpng constant C corresponds to a return value of C. =head1 Private chunks See L of L for information on the PNG standards for private chunks. To test whether your version of libpng supports C, use L with argument 'L': if (libpng_supports ('UNKNOWN_CHUNKS')) { # do something } =head2 get_chunk_malloc_max my $max = $png->get_chunk_malloc_max (); This gets the maximum amount of memory that a chunk can use. To test whether your version of libpng supports C, use L with argument 'L': if (libpng_supports ('CHUNK_MALLOC_MAX')) { # do something } This function corresponds to C in libpng =head2 set_chunk_malloc_max $png->set_chunk_malloc_max ($max); This sets the maximum amount of memory that a chunk can use. The default value of libpng 1.6.45 is 8 megabytes. To test whether your version of libpng supports C, use L with argument 'L': if (libpng_supports ('CHUNK_MALLOC_MAX')) { # do something } This function corresponds to C in libpng =head2 set_keep_unknown_chunks use Image::PNG::Const 'PNG_HANDLE_CHUNK_ALWAYS'; $png->set_keep_unknown_chunks (PNG_HANDLE_CHUNK_ALWAYS); Tell libpng not to discard unknown chunks when reading the file. =head2 get_unknown_chunks my $private_chunks = $png->get_unknown_chunks (); # Get some data from a private chunk my $chunk_three_data = $private_chunks->[3]->{data}; # Get the size of the data print length $chunk_three_data; This gets all of the private chunks from the image. The return value is an array reference containing hash references. If there are no private chunks, this returns an undefined value. There is one element of the array for each chunk member. It is necessary to call L with an appropriate value before reading the file, otherwise libpng discards unknown chunks when reading the file. Each member hash reference has the following keys: =over =item name The name of the unknown chunk, in the PNG chunk format (four bytes). =item location The location of the unknown chunk. =item data The data of the unknown chunk =back The "size" field of the PNG structure is not stored, because the "data" member of the hash contains information on its length. This function corresponds to C in libpng =head2 set_unknown_chunks $png->set_unknown_chunks (name => 'dUCk', data => 'abcdefg', location => PNG_AFTER_IDAT); ⛐πŸ€ͺ⚠ This currently does not fully function. This function corresponds to C in libpng =head1 Library version functions =head2 access_version_number my $libpng_version_number = Image::PNG::Libpng::access_version_number (); This function returns the version of the libpng library which the module is using as an integer number. This function corresponds to C in libpng. =head2 get_libpng_ver my $libpng_version = Image::PNG::Libpng::get_libpng_ver (); This function returns the version of the libpng library which the module is using. This function corresponds to C in libpng. However, it doesn't require the C argument of the C function. See L. =head1 Compression and filtering =head2 get_compression_buffer_size my $size = $png->get_compression_buffer_size (); Returns the value of the compression buffer size, which may be altered with L. =head2 set_compression_buffer_size $png->set_compression_buffer_size (100); Set the size of the buffer which zlib uses to compress or decompress the image data. It takes one argument, an integer number. This cannot be less than 6. =head2 set_compression_level $png->set_compression_level ($number); Set the compression level used to make the PNG. A value of 0 (C) corresponds to no compression at all, otherwise C<$number> may take values of 1 (C) to 9 (C), with smaller values giving faster, and larger values giving better, that is with smaller output, compression. These correspond to the -1, -2, ... -9 options to the C utility, or the compression level parameter of C. Calling with C<-1> (C) reverts to the default compression. Calling with any other number outside the range 0 to 9 results in a fatal error. This function was added to the module in version 0.49. =head2 set_compression_mem_level $png->set_compression_mem_level ($argument); ⛐πŸ€ͺ⚠ Untested function corresponding to C. Takes one integer argument. Sets the C parameter of C in zlib when writing PNG image data. Argument between 1 for minimum memory and 9 for maximum speed. The default is 8. See L. =head2 set_compression_window_bits $png->set_compression_window_bits ($argument); ⛐πŸ€ͺ⚠ Untested function corresponding to C. Takes one integer argument. Sets the C parameter of C in zlib when writing PNG image data. Argument value must be between 8 and 15 for libpng. The default is 15. See the L. =head2 set_compression_strategy $png->set_compression_strategy ($argument); ⛐πŸ€ͺ⚠ Untested function corresponding to C. Takes one integer argument. Sets the C parameter of C when writing PNG image data. Setting this with libpng overrides libpng's default behaviour of changing the value depending on the filter in use. For zlib, the argument is either 0 for default behaviour, or 1 to 4. See the L. libpng uses the default strategy 0 (C) for unfiltered image data, and 1 (C) for filtered image data. =head2 set_filter use Image::PNG::Const 'PNG_FILTER_NONE'; $png->set_filter (PNG_FILTER_NONE); This sets the filters which are allowed to be used for writing a PNG image. The possible values are =over =item PNG_NO_FILTERS =item PNG_FILTER_NONE =item PNG_FILTER_SUB =item PNG_FILTER_UP =item PNG_FILTER_AVG =item PNG_FILTER_PAETH =item PNG_ALL_FILTERS =back These can be combined using C<|> (logical or): use Image::PNG::Const ':all'; set_filter ($png, PNG_FILTER_UP | PNG_FILTER_AVG); Please see L of L for the meanings of these filter types. This function corresponds to C in libpng with the second (unused) argument omitted. See L. =head2 set_text_compression_level $png->set_text_compression_level ($argument); ⛐πŸ€ͺ⚠ Untested function corresponding to C. Takes one integer argument. As L but for compressed text. =head2 set_text_compression_mem_level $png->set_text_compression_mem_level ($argument); ⛐πŸ€ͺ⚠ Untested function corresponding to C. Takes one integer argument. As L but for compressed text. =head2 set_text_compression_window_bits $png->set_text_compression_window_bits ($argument); ⛐πŸ€ͺ⚠ Untested function corresponding to C. Takes one integer argument. As L but for compressed text. =head2 set_text_compression_strategy $png->set_text_compression_strategy ($argument); ⛐πŸ€ͺ⚠ Untested function corresponding to C. Takes one integer argument. As L but for compressed text. =head1 Other chunks These routines deal with the other possible chunks of PNGs. The getter and setter routines for all other chunks are designed so that the return value of C is able to be used directly as the value for C, so the values of chunks can easily be copied from one PNG to another. my $values = $png1->get_wXYZ (); $png2->set_wXYZ ($values); If the chunk is not present, or if the chunk is not supported by the user's version of libpng, the return value of C is the undefined value. =head2 bKGD The background color of the PNG image. See L of L for information on the PNG standards for the background chunk. =head3 get_bKGD my $bkgd = $png->get_bKGD (); Get the bKGD (background) chunk of the image. The return value is a hash with the following keys, depending on the color type of the image: =over =item index For palette color types, this is the offset into the palette. =item gray For grayscale color types. =item red =item green =item blue =back This function corresponds to C in libpng with a hash function instead of a C struct. =head3 set_bKGD $png->set_bKGD ($bkgd); Set the bKGD (background) chunk of the image. C<$bkgd> is a hash reference. The keys of the hash reference are as described in L. This function corresponds to C in libpng with a hash function instead of a C struct. =head2 cHRM See L of L "cHRM Primary chromaticities and white point". =head3 get_cHRM my $cHRM = $png->get_cHRM (); Get the cHRM chunk as a hash reference. The keys of the hash are white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y. The values of the hash are floating point numbers between 0 and 1. This function corresponds to C in libpng with a hash reference supplying the arguments. The hash's keys correspond to the names of the C arguments in libpng. =head3 get_cHRM_XYZ my $cHRM = $png->get_cHRM_XYZ (); Get the cHRM chunk as a hash reference for the XYZ color space. The keys of the hash are red_x, red_y, red_z, green_x, green_y, green_z, blue_x, blue_y, blue_z. The values of the hash are floating point numbers between 0 and 1. This function corresponds to C in libpng with a hash reference supplying the arguments. The hash's keys correspond to the names of the C arguments in libpng. =head3 set_cHRM $png->set_cHRM (\%cHRM); Set the cHRM chunk from a hash reference. The keys of the hash are as for L. The values are floating point numbers between 0 and 1. This function corresponds to C in libpng with a hash reference instead of the C arguments. =head3 set_cHRM_XYZ $png->set_cHRM_XYZ (\%cHRM); Set the cHRM chunk from a hash reference for the XYZ color space. The keys of the hash are as for L. The values are floating point numbers between 0 and 1. The C values C, C, and C should sum to 1. If you supply values outside the allowed range, libpng corrects them silently on writing rather than producing an error. This function corresponds to C in libpng with a hash reference instead of the C arguments. =head2 eXIf The C chunk is an extension to the PNG specification. See L. Support for this chunk was added in version 0.50 of this module. =head3 get_eXIf my $exif = $png->get_eXIf (); This retrieves the C chunk from C<$png> but does not process the internal information. =head3 set_eXIf $png->set_eXIf ($exif); libpng checks whether the chunk's first two bytes are either C for little-endian (from Intel) or C for big-endian (from Motorola) then adds the entire chunk, including the first two bytes, to the PNG. ⛐πŸ€ͺ⚠ As of December 2020, there appears to be a bug in libpng in which the eXIf chunk is added twice, causing a warning of the form C on reading a PNG file back in. See L. =head2 gAMA See L of L. =head3 get_gAMA my $gamma = $png->get_gAMA (); Get the gamma value or gAMA chunk. The return value is a floating-point number. This function corresponds to C in libpng =head3 set_gAMA $png->set_gAMA (0.2); Set the gamma value or gAMA chunk. This function corresponds to C in libpng =head2 hIST See L of L. =head3 get_hIST my $hist = $png->get_hIST (); If the PNG file contains a histogram, the return value is array reference, otherwise it is the undefined value. The number of entries in the array reference is the same as in the palette. This function corresponds to C in libpng =head3 set_hIST $png->set_hIST (\@hist); Set the histogram of frequencies of the colors of a paletted (L) image. The entries of the histogram are 16 bit unsigned integers, so the maximum value that can be entered is 65535 = 2^16 - 1. Larger numbers and floating point numbers will cause a warning to be printed and the value to be set to zero. The histogram must have exactly the same number of entries as the palette or the call will fail with a warning. A histogram cannot be added to an image without a palette. A call to set_hIST for an image without a palette will cause a warning and return without setting the value. (I'm not sure of the best form of error handling for this function so it may change in future versions to have errors for a bad histogram rather than warnings.) This function corresponds to C in libpng =head2 iCCP See L of L. =head3 get_iCCP my $iccp = $png->get_iCCP (); The return value is a hash with two keys, =over =item name The name of the profile. =item profile The color profile. =back The C value, which is always 0, is not returned. See L. This function corresponds to C in libpng. =head3 set_iCCP $png->set_iCCP ({name => 'name', profile => 'profile'}); This function corresponds to C in libpng. For details of the arguments, see L. A C argument, which must always be 0 anyway, is ignored. See L. =head2 oFFs This is an extension to the PNG specification. See L. =head3 get_oFFs my $phys = $png->get_oFFs (); Get oFFs chunk. Return value is a hash reference This function corresponds to C in libpng =head3 set_oFFs $png->set_oFFs ({x_offset => 1, y_offset => 1, unit_type => 0}); Set oFFs chunk. See the specification linked above for the meanings of the parameters. If C is not 0 or 1, a warning is produced. This function corresponds to C in libpng =head2 pCAL pCAL is an extension of the PNG specification which allows one to associate pixels in the PNG image with non-image data such as a heat map. See L. To test whether your version of libpng supports C, use L with argument 'L': if (libpng_supports ('pCAL')) { # do something } =head3 get_pCAL my $pcal = $png->get_pCAL (); The return value is a hash reference with the following keys: =over =item params If this exists, its value is a reference to an array containing the parameter list of the pCAL chunk, which are floating point numbers. Within the PNG file chunk, these parameters are stored as strings representing floating point numbers, but you can pass in Perl floating point numbers rather than strings. The number of parameters you should set is fixed by the C parameter. Refer to the PNG specification for full details. =item purpose The purpose string of the pCAL chunk. =item type The equation type as a number, from 0 to 3. See the PNG specification for the meanings. Other numbers cause an error. =item units The units as a string. See the PNG specification for details. =item x0 The zero value for the equation, an integer. =item x1 The max value for the equation, an integer. =back This function corresponds to C in libpng =head3 set_pCAL $png->set_pCAL (\%values); See L for the parameters of C<%values>. This function corresponds to C in libpng =head2 pHYs See L of L. =head3 get_pHYs my $phys = $png->get_pHYs (); The return value is a hash reference with the keys =over =item res_x =item res_y =item unit_type Is either 0 or 1. =back This function corresponds to C in libpng =head3 set_pHYs $png->set_pHYs ({res_x => 1, res_y => 1, unit_type => 1}); This function corresponds to C in libpng =head2 PLTE See L of L for information on the PNG standards for the palette chunk. =head3 get_palette_max my $pmax = $png->get_palette_max (); If your libpng supports it, this will return the maximum palette index found in the image, or "-1" if the palette was not checked, or "0" if no palette was found. To test whether your version of libpng supports C, use L with argument 'L': if (libpng_supports ('GET_PALETTE_MAX')) { # do something } ⛐πŸ€ͺ⚠ This function is implemented but so far it is not very clear to me what it does, since, for example, it returns zero for the test image F which is an image with a fully-used 256-color palette. I've L, but so far nobody has responded. =head3 get_PLTE my $colors = $png->get_PLTE (); # Get the green value of the twentieth entry in the palette. my $green = $colors->[20]->{green}; This function gets the palette from the PNG. The return value is an array reference containing the palette. This array contains hash references with the values "green", "blue" and "red" for the color of each pixel in the palette. If the PNG has no palette, it returns an undefined value. A PNG image may or may not contain a palette. To check whether the image contains a palette, use something of the following form: use Image::PNG::Const ':all'; my $color_type = $png->get_color_type (); if ($color_type == PNG_COLOR_TYPE_PALETTE) { # The PNG uses a palette. } A PNG image may also contain a palette even when the "color_type" does not indicate that. To check for that case, use L. This function corresponds to C in libpng. =head3 set_PLTE $png->set_PLTE ($palette); Set the palette of C<$png>. The argument is an array reference containing hash references. There is one hash reference for each palette entry. The hash references contain three fields, red, green, and blue, corresponding to the pixel value for that palette entry. Other values in the hash references are ignored. For example, $png->set_PLTE ([{red => 1, green => 99, blue => 0x10}, {red => 0xFF, green => 0xFF, blue => 0xFF}]); creates a palette with two entries in C<$png>. This function corresponds to C in libpng. =head2 sBIT See L of L. =head3 get_sBIT my $sbit = $png->get_sBIT (); The return value is a hash reference containing integer values for the keys C, C, C, C and C, depending on the C of C<$png>. ⛐πŸ€ͺ⚠ Prior to version 0.50 of this module, get_sBIT wrote values of 0 for all of the keys, regardless of the C, causing errors in some circumstances. From version 0.50, hash keys are not entered if the C of the image makes them invalid. This function corresponds to C in libpng =head3 set_sBIT $png->set_sBIT ({red => 1, blue => 2, green => 3}); The argument is a hash reference containing integer values for the keys C, C, C, C, and C, as required by the C of C<$png>. This function corresponds to C in libpng =head2 sCAL This is an extension to the PNG specification. See L. To test whether your version of libpng supports C, use L with argument 'L': if (libpng_supports ('sCAL')) { # do something } =head3 get_sCAL my $scal = $png->get_sCAL (); The returned hash value contains the following keys: =over =item unit The unit type, which is either PNG_SCALE_UNKNOWN, PNG_SCALE_METER, or PNG_SCALE_RADIAN. =item width The width, as a string. =item height The height, as a string. =back This function corresponds to C in libpng. Note that this uses the sCAL_s function rather than the get_sCAL and the returned values are the strings themselves rather than parsed numbers. =head3 set_sCAL $png->set_sCAL ($scal); C<$scal> is a hash reference containing the keys described in L. This function corresponds to C in libpng. Note that this uses the C function rather than C and the input values are the strings themselves rather than numbers. =head2 sPLT See L of L. =head3 get_sPLT ⛐πŸ€ͺ⚠ Provisional. See L for documentation, the return value is like the input of that. =head3 set_sPLT $png->set_sPLT ([{ name => 'palette', depth => 8, entries => [{red => 1, blue => 2},]}]); Set suggested palettes. The input is an array reference containing hash references with the following fields: =over =item name The name of the suggested palette. =item depth The depth of the suggested palette. =item entries The entries of the palette. This is an array reference containing hash references with keys as follows: =over =item red =item blue =item green =item frequency =item alpha =back =back The field C which is returned by L does not need to be specified, it is calculated from the length of C. =head2 sRGB See L of L. =head3 get_sRGB my $sRGB = $png->get_sRGB (); The return value is an integer number corresponding to one of the following: =over =item PNG_sRGB_INTENT_SATURATION =item PNG_sRGB_INTENT_PERCEPTUAL =item PNG_sRGB_INTENT_ABSOLUTE =item PNG_sRGB_INTENT_RELATIVE =back This function corresponds to C in libpng =head3 set_sRGB $png->set_sRGB ($srgb); C<$srgb> is one of the values described in L. This function corresponds to C in libpng =head2 tIME See L of L for information on the PNG standards for time stamp information. =head3 get_tIME my $time = $png->get_tIME (); if ($time && $time->{year} < 2005) { warn "Your PNG is now getting old. Don't forget to oil it to prevent rust."; } The return value is either the undefined value, if no C chunk? =item FIXED_POINT =item FIXED_POINT_MACRO =item FLOATING_ARITHMETIC =item FLOATING_POINT =item FORMAT_AFIRST =item FORMAT_BGR =item gAMA Does the libpng support the L chunk? =item GAMMA =item GET_PALETTE_MAX Does your libpng support L? =item HANDLE_AS_UNKNOWN =item HANDLE_AS_UNKNOWN =item hIST Does the libpng support the L chunk? =item iCCP Does the libpng support the L chunk? =item INCH_CONVERSIONS =item INFO_IMAGE =item IO_STATE =item iTXt Does the libpng support international text? =item MIPS_MSA_API =item MNG_FEATURES =item oFFs Does the libpng support the L chunk? =item pCAL Does the libpng support the L extension? =item PEDANTIC_WARNINGS =item pHYs Does the libpng support the L chunk? =item POINTER_INDEXING =item POWERPC_VSX_API =item PROGRESSIVE_READ =item READ Can libpng read PNGs? =item READ_16_TO_8 =item READ_ALPHA_MODE See L. =item READ_BACKGROUND See L. =item READ_BGR See L. =item READ_COMPOSITE_NODIV =item READ_COMPRESSED_TEXT =item READ_EXPAND =item READ_EXPAND_16 =item READ_FILLER =item READ_GAMMA See L. =item READ_GRAY_TO_RGB =item READ_INTERLACING =item READ_INT_FUNCTIONS =item READ_INVERT =item READ_INVERT_ALPHA =item READ_OPT_PLTE =item READ_PACK =item READ_PACKSWAP =item READ_QUANTIZE =item READ_RGB_TO_GRAY =item READ_SCALE_16_TO_8 =item READ_SHIFT =item READ_STRIP_16_TO_8 =item READ_STRIP_ALPHA =item READ_SWAP =item READ_SWAP_ALPHA =item READ_tEXt =item READ_TRANSFORMS =item READ_USER_TRANSFORM =item READ_zTXt =item SAVE_INT_32 =item SAVE_UNKNOWN_CHUNKS =item sBIT Does the libpng support the L chunk? =item sCAL Does the libpng support the L extension? This actually tests for the presence of the C/C functions, so its behaviour is dependent on other factors for versions 1.2 and 1.4 of libpng. =item SEQUENTIAL_READ =item SETJMP =item SET_OPTION =item SET_UNKNOWN_CHUNKS =item SET_USER_LIMITS =item SIMPLIFIED_READ =item SIMPLIFIED_READ_AFIRST =item SIMPLIFIED_WRITE =item SIMPLIFIED_WRITE_AFIRST =item SIMPLIFIED_WRITE_BGR =item SIMPLIFIED_WRITE_STDIO =item sPLT Does the libpng support L chunks? =item sRGB Does the libpng support the L chunk? =item STDIO =item STORE_UNKNOWN_CHUNKS =item TEXT Does the libpng support text? =item tEXt Does the libpng support tEXt chunks? =item tIME Does the libpng support the L chunk? =item TIME_RFC1123 =item tRNS Does the libpng support the L chunk? =item UNKNOWN_CHUNKS Does the libpng support unknown chunks (see L)? =item USER_CHUNKS =item USER_LIMITS Does the libpng support L and the related functions L, and L? =item USER_LIMITS =item USER_MEM =item USER_TRANSFORM_INFO =item USER_TRANSFORM_PTR =item WARNINGS =item WRITE Can libpng write pngs? =item WRITE_BGR =item WRITE_COMPRESSED_TEXT =item WRITE_CUSTOMIZE_COMPRESSION Does the libpng support L and similar functions? ⛐πŸ€ͺ⚠ It's not very clear that this returns a useful value, since L seems to be in libpngs from at least as far back as C<1.5.1>, and yet this macro was only added to libpng in version C<1.6.13>. =item WRITE_CUSTOMIZE_ZTXT_COMPRESSION Does the libpng support L and similar functions? =item WRITE_FILLER =item WRITE_FILTER =item WRITE_FLUSH =item WRITE_FLUSH_AFTER_IEND =item WRITE_INTERLACING =item WRITE_INT_FUNCTIONS =item WRITE_INVERT =item WRITE_INVERT_ALPHA =item WRITE_OPTIMIZE_CMF =item WRITE_PACK =item WRITE_PACKSWAP =item WRITE_SHIFT =item WRITE_SWAP =item WRITE_SWAP_ALPHA =item WRITE_TRANSFORMS =item WRITE_USER_TRANSFORM =item WRITE_WEIGHTED_FILTER =item zTXt Does the libpng support C chunks? =back =head2 png_compare if (png_compare ('a.png', 'b.png') == 0) { print "The PNGs are the same.\n"; } This compares the image data in two PNGs and returns 0 if they contain exactly the same image data, or 1 if they contain different image data. For a more detailed comparison, see L. This does not compare to see if the PNG files "look like" each other, but whether each pixel contains exactly the same values. Please see L for a looser comparison of images. This uses the "expand" transform of libpng to read both the images, so it is able to compare images of different color types. It compares the alpha values as well as the color pixels. See L for an example of comparing an RGB and a grayscale image. =head2 read_struct if ($png->read_struct ()) { warn "Can't write this, use copy_png to copy it"; } This returns a true value if C<$png> was created with L or allied functions like L, and a false value if C<$png> was created with L or allied functions like L. =head2 set_chunk $png->set_chunk ('tIME', $timechunk); Set the specified chunk. This produces a fatal error if given an C (image data) chunk, use L instead. This produces a fatal error if given an unknown chunk name. The first argument is the chunk name and then the second argument is a scalar containing whatever the chunk requires, for example a hash reference for the C