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

Node / Raster Batch Output · guide

Compress & palette

Current Apexify.js 6.0.0 documentation for Compress & palette.

apexify.jsRuntime: nodeCURRENTSince 6.0.0

Sharp-backed helpers exposed as await painter.image.compress(image, options?) and await painter.image.extractPalette(image, options?) (lib-next/output/compression.ts).

Sources:** Buffer, http(s) URL, or filesystem path (**joined with process.cwd() when not absolute / URL).


compress(image, options?)

CompressionOptions

FieldDefaultNotes
quality90Passed to jpeg, webp, avif pipelines.
formatjpegjpeg **`
maxWidth / maxHeight—fit: 'inside', withoutEnlargement: true.
progressivefalseJPEG progressive scan.

Returns encoded Buffer (not necessarily PNG).

SOURCEtypescript
typescript
Studio
const webp = await painter.image.compress(buf, { format: 'webp', quality: 82, maxWidth: 1024 });

extractPalette(image, options?)

Downsamples internally to ~200×200 raw RGB, then clusters.

PaletteOptions

FieldDefaultNotes
count10Target swatch count (algorithms clamp / approximate).
methodkmeanskmeans (iterative) **`
formathexhex **`

Return shape

Array<{ color: string; percentage: number }> sorted descending by percentage.

SOURCEtypescript
typescript
Studio
const swatches = await painter.image.extractPalette('./hero.png', {  count: 8,  method: 'median-cut',  format: 'hsl',});

Operational notes

  • Network / disk IO failures surface as compress failed: / extractPalette failed: wraps.
  • extractPalette percentage derives from clustered pixel assignments vs total sample count (see implementation for details).

Next steps