Skip to content
Apexify.jsDocs
Apexify.js version v5.4.5

Node / Gif Animation · guide

onEnd, return values & cancellation

Current Apexify.js 6.0.0 documentation for onEnd, return values & cancellation.

apexify.jsRuntime: nodeCURRENTSince 6.0.0

onEnd

SOURCEtypescript
typescript
Studio
onEnd?: (  finalFrameBuffer: Buffer,  painter: unknown) => Promise<Buffer | undefined>;

The runtime passes the active ApexPainter instance as the second argument.

finalFrameBuffer is a PNG snapshot of the last fully composited encoder canvas after frame sizing, watermarking, and textOverlay rendering. Use it for a poster/still preview or another derived static result.

onEnd runs only after GIF encoding has finished and the selected primary output has been drained/validated.


Return values

Without a static onEnd result:

outputFormatPrimary result
bufferGIF Buffer
base64base64 string containing GIF bytes
attachmentGIFAttachment[] with Buffer-backed .gif data and image/gif MIME
fileundefined; file already written to outputFile

If onEnd returns a Buffer:

  • buffer → { gif: Buffer, static: Buffer }
  • base64 → { gif: string, static: Buffer }
  • attachment → { gif: GIFAttachment[], static: Buffer }
  • file → the returned static Buffer only; the GIF remains at outputFile

Unlike the old attachment shortcut, Phase 7 does invoke onEnd for attachment output. Attachment creation drains and validates the encoder output first.

SOURCEtypescript
typescript
Studio
const result = await painter.createGIF(frames, {  outputFormat: 'attachment',  attachmentName: 'preview',  width: 640,  height: 360,  onEnd: async (lastFramePng) => lastFramePng,}); // result.gif[0].name === 'preview.gif'// result.gif[0].contentType === 'image/gif'// result.static is the final composited PNG Buffer

skipResizeWhenDimensionsMatch

Public sizing is always deterministic stretch-to-output.

ValueBehaviour
true or omittedIf decoded source dimensions already match output dimensions, draw directly without redundant sized scaling.
falseUse the explicit sized draw path even when dimensions match.

This is an optimization switch, not a fit/crop mode. Sources whose size differs from the GIF canvas are stretched to options.width × options.height in either case.


Cancellation (signal)

GIFOptions.signal accepts an AbortSignal.

A cancellation is checked before generated-frame startup and between frame pulls/processing steps, and is forwarded into remote media resolution. On failure/cancellation:

  • no additional generated frames are requested;
  • encoder/output streams are destroyed where applicable;
  • pending output completion is observed to avoid unhandled stream failures;
  • a partially written outputFile is removed.

A signal that is already aborted prevents onStart from running.


Validation recap

Important Phase 7 rules include:

  • outputFormat must be file, buffer, base64, or attachment.
  • file requires a non-empty outputFile.
  • attachmentName, when present, must be a filename rather than a path.
  • width and height must be supplied together and fit GIF resource limits.
  • repeat allows -1, 0, or a finite positive repeat count within the encoder range.
  • quality is an integer from 1 through 30.
  • frame/default delays must be finite and within the GIF delay range; zero delay is allowed.
  • static frame lists must be non-empty and each frame must provide exactly one source.
  • generated arrays/streams cannot exceed configured generated-frame/GIF limits.
  • passing both a non-empty static list and onStart is invalid.

Structured Apexify input/resource/network/decode/process errors are used for these failure classes rather than leaking arbitrary backend errors as the public contract.

Next steps