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

Node / Gif Animation · guide

Chroma transparency & frame disposal

Current Apexify.js 6.0.0 documentation for Chroma transparency & frame disposal.

apexify.jsRuntime: nodeCURRENTSince 6.0.0

GIF transparency in this API is indexed-color chroma transparency: the encoder selects one palette color as transparent for a frame. It is not per-pixel alpha in the encoded GIF.


transparentColor

Global: GIFOptions.transparentColor
Per frame: GIFInputFrame.transparentColor / GIFEncodedFrame.transparentColor

Accepted forms:

  • #RRGGBB
  • RRGGBB
  • 0xRRGGBB
  • #RRGGBBAA / RRGGBBAA (the encoder uses the RGB portion)
  • a 24-bit integer from 0x000000 through 0xFFFFFF
  • null to explicitly disable chroma transparency

Invalid strings, negative numbers, non-integers, and numeric values above 0xFFFFFF are rejected before encoding.

Precedence

For every frame:

SOURCEtext
text
frame.transparentColor  if definedelse options.transparentColor  if definedelse no transparent color

Because null is distinct from undefined, a frame can explicitly turn off a global transparent color:

SOURCEtypescript
typescript
Studio
await painter.createGIF(  [    { buffer: keyedFrame, transparentColor: '#00ff00' },    { buffer: opaqueFrame, transparentColor: null },  ],  {    outputFormat: 'buffer',    width: 480,    height: 270,    transparentColor: '#ff00ff',  });

Disposal (GIFDisposalMethod)

Supported codes are:

CodeGIF meaning
0No disposal specified
1Do not dispose; leave the frame in place
2Restore the frame area to background
3Restore to the previous composited state

Per-frame dispose overrides GIFOptions.defaultDispose.

When neither is supplied, Apexify resets the encoder disposal mode deterministically for each frame:

  • 2 when no transparent color is active
  • 0 when chroma transparency is active

This reset matters because encoder settings are stateful. A frame-local disposal/transparency override does not silently leak into later frames.


Quantization caveat

The requested transparent RGB value is matched against the quantized GIF palette. Anti-aliased edges may contain neighboring colors and therefore remain partially visible. For chroma-key workflows, use hard edges or prepare the source frames accordingly.

Next steps