An animated PNG adds three chunks to an ordinary PNG, and since the Third Edition these are part of the standard. A reader without animation support skips them and shows the default image.
acTL, animation control
Marks the file as animated. It must come before the image data, and appear once.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | Number of frames | The number of fcTL chunks; 0 is not allowed, and a count that differs from the number of fcTL chunks is an error. |
| 4 | 4 | Number of plays | How many times the animation plays; 0 for forever. It rests on the last frame. |
fcTL, frame control
Exactly one for each frame, 26 bytes of data. One may come before the image data, making the default image the animation’s first frame; the rest come after it.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | Sequence number | See below. |
| 4 | 4 | Width | The frame’s width, greater than 0. |
| 8 | 4 | Height | The frame’s height, greater than 0. |
| 12 | 4 | X offset | Where the frame’s left edge is on the canvas. |
| 16 | 4 | Y offset | Where the frame’s top edge is on the canvas. |
| 20 | 2 | Delay numerator | How long the frame shows, with the denominator, in seconds. 0 means the next frame follows as soon as it can. |
| 22 | 2 | Delay denominator | 0 stands for 100, so the numerator counts hundredths. |
| 24 | 1 | Dispose operation | See below. |
| 25 | 1 | Blend operation | See below. |
The frame must fit the canvas: x + width is no more than the image’s width and
y + height no more than its height. The default image, if it is a frame, must be at 0, 0 and
have the image’s full size. Each frame takes the image’s colour type, bit depth and palette from
the chunks before the first IDAT; only the width and height come from fcTL. When there is a pHYs chunk,
the frame offsets are scaled by it just as the image is.
Dispose operations
What happens to the frame’s area of the canvas after the frame has been shown, before the next is drawn.
| Value | Name | Effect |
|---|---|---|
| 0 | None | The canvas is left as it is. |
| 1 | Background | The frame’s area is cleared to transparent black. |
| 2 | Previous | The frame’s area is put back as it was before this frame. |
A first frame with dispose 2 is treated as 1, since there is nothing to go back to.
Blend operations
| Value | Name | Effect |
|---|---|---|
| 0 | Source | The frame replaces the canvas in its area, alpha included. |
| 1 | Over | The frame is drawn over the canvas using its alpha. |
For the first frame the two are the same, since the canvas starts each play cleared to transparent black.
fdAT, frame data
The compressed data of every frame that is not the default image. When an fcTL comes before IDAT the default image is frame 0 and needs no fdAT; otherwise the default image is not part of the animation, and every frame, the first included, has its data in fdAT. Each such frame needs at least one fdAT chunk. It is laid out just as IDAT is, after a sequence number, and must come after the image data. An fdAT chunk may not be zero length, since it always holds its 4-byte sequence number, but its frame data may be empty.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | Sequence number | See below. |
| 4 | The rest | Frame data | Part of the frame’s zlib stream, as an IDAT holds the main image’s. |
A frame’s data is all its fdAT chunks joined in sequence order. It inflates to filtered scanlines, in the same form as the image’s, including filter bytes and, for an interlaced image, the Adam7 passes.
Sequence numbers
fcTL and fdAT share one count, starting from 0. A chunk out of order is an error, so a reader can tell when chunks have been lost or moved.
In the explorer
Each frame has a picture of the canvas as it stands after that frame, drawn over the frames before it, and each frame’s data can be shown as its Deflate stream.