AnimationHandle — APNG / WebP animation builder
Diese Seite ist derzeit nur englisch — die JSDoc-Kommentare in der Engine sind englisch verfasst. Eine deutsche Auto-Generierung folgt, sobald die Methoden mit
@apidoc-de-Tags ausgestattet sind. — Zur Übersicht
AnimationHandle accumulates frames into an animated PNG or WebP. Returned by Engine.animation(); finalise with save().
Classes
AnimationHandle
Multi-frame animation container backed by Rust ops::animation.
Frames are added one at a time (each call copies the source
image's pixels — the source ImageHandle stays valid; caller
frees both when done). Currently exports as APNG; WebP-anim and
MP4 land in later phases.
const anim = Engine.animation(800, 600, { loop: 0 });
const logo = Engine.loadImage(LOGO);
for (let i = 0; i < 10; i++) {
const f = logo.clone().brightness(i / 10);
anim.addFrame(f, { delay: 50 });
f.free();
}
anim.saveAPNG(OUTPUT);
anim.free();
logo.free();
Accessors
frameCount
Get Signature
get frameCount(): number;
Returns
number
height
Get Signature
get height(): number;
Returns
number
id
Get Signature
get id(): number;
Returns
number
width
Get Signature
get width(): number;
Returns
number
Methods
addFrame()
addFrame(img, opts?): this;
Append a frame. The image's pixels are COPIED into the
animation; img stays valid for further use. Frames larger
than the canvas, or offsets that push them off-canvas, are
silently clipped to the canvas-frame intersection.
Parameters
| Parameter | Type | Description |
|---|---|---|
img |
ImageHandle |
Source ImageHandle (stays owned by caller). |
opts? |
{ delay?: number; offsetX?: number; offsetY?: number; } |
- |
opts.delay? |
number |
Frame duration in milliseconds. Default 100. |
opts.offsetX? |
number |
Top-left placement on canvas. Default 0. |
opts.offsetY? |
number |
Top-left placement on canvas. Default 0. |
Returns
this
free()
free(): void;
Release the underlying buffers.
Returns
void
saveAPNG()
saveAPNG(keyOrPath): this;
Encode and write APNG bytes. keyOrPath is either a registered
output slot (then bytes go to the binary output registry the
GUI / CLI reads) or a filesystem path.
Parameters
| Parameter | Type |
|---|---|
keyOrPath |
string |
Returns
this
saveTIFF()
saveTIFF(keyOrPath): this;
Encode and write the frame list as a multi-page TIFF — each
frame becomes one IFD (Image File Directory), the same mechanism
scanned documents and scientific image stacks use to carry many
images in one file. The per-frame delay metadata is dropped
(TIFF has no standard tag for it) but every frame is stored at
full RGBA8 bit-fidelity with no inter-frame compression — handy
when you want frames preserved exactly rather than played back.
Typical fits: a list of frames to ship as a single multi-page file, document scans, time-series / Z-stack scientific imagery.
Parameters
| Parameter | Type | Description |
|---|---|---|
keyOrPath |
string |
Output slot or filesystem path. |
Returns
this
saveWebP()
saveWebP(keyOrPath, opts?): this;
Encode and write animated WebP bytes. Often substantially smaller than APNG, especially in lossy mode.
Parameters
| Parameter | Type | Description |
|---|---|---|
keyOrPath |
string |
Output slot or filesystem path. |
opts? |
{ keyframes?: number | "none" | "auto" | "all"; lossy?: boolean; quality?: number; } |
- |
opts.keyframes? |
number | "none" | "auto" | "all" |
How often a full key frame is written — "all" (every frame), "none", or a maximum distance in frames. Default "auto". This is a correctness knob, not a size knob. libwebp encodes each frame as a delta and, in lossy mode, treats almost-equal pixels as unchanged. During a slow cross fade every step stays under that threshold, so stale blocks survive — with content from much older frames (B-20260923-01). Key frames end the chain. |
opts.lossy? |
boolean |
If true, use VP8 lossy compression. Default false. |
opts.quality? |
number |
Quality ∈ [0..100]. Default 80. Lossless mode uses quality as a method-level effort hint (still bit-correct). |
Returns
this