NAME

Imager::File::APNG - read and write APNG image files

SYNOPSIS

use Imager;
use Imager::File::APNG;

my @frames = Imager->read_multi(file => "foo.png", type => "apng)
  or die Imager->errstr;

Imager->write_multi({
    file => "foo.png",
    type => "apng"
    apng_delay => 1/60,
  }, @frames)
  or die Imager->errstr;

DESCRIPTION

Implements APNG support for Imager.

To write an APNG image the type parameter needs to be explicitly supplied.

LIMITATIONS

  • Due to the limitations of APNG all images are written as the same type, eg. all RGBA, or all Grayscale, or all paletted with the same palette. Imager::File::APNG will upgrade all supplied images to the greatest common layout.

Image tags

The i_format tag is deliberately set to png on reading an APNG image.

Tags common to reading and writing:

  • apng_hidden - set on all images when reading, only has an effect on the first image when writing. If non-zero for the first image it will be hidden from the animation.

  • apng_num_plays - set on all images when reading, only used from the fisrt image when writing. Specifies the number of time to repeat the animation. If zero repeat forever. Default: 0.

  • apng_xoffset, apng_yoffset - the position of the frame within the canvas, which is defined by the first image. The frame as positioned by these offsets must be contained within the canvas dimensions. Both default to 0.

  • apng_dispose - for each animation frame, one of 0, 1, or 2, or alternatively none, background or previous when writing. Default: 0.

  • apng_blend - for each animation frame, one of 0 or 1, or alternatively source or over when writing. Default: 0.

  • apng_delay - for each animation frame, the delay in seconds, including fractional seconds, that the frame is displayed for. This overrides apng_delay_num and apng_delay_den. This is currently converted to a fraction out of 1000 when written to the file.

  • apng_delay_num, apng_delay_den - for each animation frame, the delay in seconds, including fractional seconds, that the frame is displayed for, as a rational number apng_delay_num / apng_delay_den . Default: 1/60. Ignored if apng_delay is set. All three tags are set on read.

TODO

Support paletted images. This will require that all the images have the same palette.

Optionally optimize frame generation from the source images, eg, trimming common pixels between the canvas at that point.

Optionally generate a common palette across all the frames. This should work with the above.

Provide a tool to convert optimized frames read from a file into full frames.

AUTHOR

Tony Cook <tonyc@cpan.org>

SEE ALSO

Imager, <Imager::Files>.