Animated PNG Creator v1.6 documentation
Field summary
| public $play_count = 0 | Defines the number of plays. 0 indicates infinite playing. |
| public $save_alpha = true | The flag to save the alpha channel information. Defines whether to save the alpha channel or not. |
| public $save_time = false | The flag to save the creation time to the file (tIME chunk). |
| public $transparent_color = false | This property defines the transparent color of the animation. When it is set to false, no transparent color is used. Here is an example how to set it:
$animation = new APNG_Creator(); $animation->transparent_color = array(0, 0, 0); // the black color will be transparent (RGB)
This property is ignored if the $save_alpha property is set to true. |
| public $background_color = array(255, 255, 255, 127) | The default background of the animation frames. It is useful when the default image if smaller than the buffer. |
Method summary
Detailed informations
public function add_image($img, $position = "MIDDLE_CENTER", $delay = 1000, $dispose_op = 0, $blend_op = 0, $part_of_anim = true)
Adds a new image to the animation.
Parameters:
$image => the image that will be added to the animation
$position => the position of the frame according to the buffer. It can be given as an array containing the x and y offsets of the frame, or as a string using the following positioning phares:

$delay => the delay before displaying the next frame. Can be set in milliseconds or in seconds as a fraction in numerator / denominator form
Example:
$animation->add_image($image1, "MIDDLE_RIGHT", 500); // the delay is set to 500 milliseconds
$animation->add_image($image1, "MIDDLE_RIGHT", array(1, 2)); // the delay is set to (1 / 2) seconds - the same results
$dispose_op => specifies how the output buffer should be changed at the end of the delay (before rendering the next frame). There are 3 options:
| Value | Option name |
| 0 | APNG_DISPOSE_OP_NONE |
| 1 | APNG_DISPOSE_OP_BACKGROUND |
| 2 | APNG_DISPOSE_OP_PREVIOUS |
- APNG_DISPOSE_OP_NONE: no disposal is done on this frame before rendering the next; the contents of the output buffer are left as is.
- APNG_DISPOSE_OP_BACKGROUND: the frame's region of the output buffer is to be cleared to fully transparent black before rendering the next frame.
- APNG_DISPOSE_OP_PREVIOUS: the frame's region of the output buffer is to be reverted to the previous contents before rendering the next frame.
$blend_op => specifies whether the frame is to be alpha blended into the current output buffer content, or whether it should completely replace its region in the output buffer. There are 2 options:
| Value | Option name |
| 0 | APNG_BLEND_OP_SOURCE |
| 1 | APNG_BLEND_OP_OVER |
To understand this property, see the following example:
| APNG_BLEND_OP_SOURCE | APNG_BLEND_OP_OVER |
 |  |
$part_of_anim => defines whether the default image is part of the animation or not. It is ignored in case of the other images.
Examples:
$animation = new APNG_Creator();
$animation->add_image($image1, null, 1000, 0, 0); // delay is set to 1 ms, offset is calculated as "MIDDLE_CENTER"
$animation->add_image($image2, array(4, 4), 1000, 0, 0); // delay is set to 1 ms, offsets are 4px, 4px
$animation->add_image($image3, null, array(1, 1000), 0, 0); // delay is set to 1 ms, but in the fraction form
public function save($filename = "")
Saves the animation to a PNG file.
Parameters:
$filename => the name of the output file (including the path)
public function destroy_images()
Destroys all of the images added to the animation using the GD imagedestroy() function.
Paremeters:
No parameters.
What is the buffer?
According to the
APNG specification:
The "output buffer" is a pixel array with dimensions specified by the width and height parameters of the PNG `IHDR` chunk. Conceptually, each frame is constructed in the output buffer before being composited onto the canvas. The contents of the output buffer are available to the decoder. The corners of the output buffer are mapped to the corners of the canvas.
The width of the buffer will equal to the maximum width dimension in the collection of frames.
The height of the buffer will equal to the maximum height dimension in the collection of frames.
All the frames are positiones according to this buffer. The following drawing will explain how a frame is positioned:

BUFFER.width = max(image1.width, image2.width, ... , imageN.width);
BUFFER.height = max(image1.height, image2.height, ... , imageN.height);
Transparency without alpha channel
If the animation containes only fully transparent and fully opaque areas, you don't need to save tha alpha channel informations to the file. You can define one transparent color for all frames in the animation.
Example:
$animation = new APNG_Creator();
$animation->save_alpha = false; // IMPORTANT! The default value for $save_alpha is true
$animation->transparent_color = array(255, 255, 255); // the white color will be transparent
// ...