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

Node / Raster Batch Output · guide

Stitch & collage

Current Apexify.js 6.0.0 documentation for Stitch & collage.

apexify.jsRuntime: nodeCURRENTSince 6.0.0

await painter.image.stitchImages(images, options?) concatenates images horizontally, vertically, or on a square-ish grid. await painter.image.createCollage(images, layout) lays out sized cells as a grid, shortest-column masonry, or carousel with backgrounds and optional rounded clips.

Implementation: lib-next/output/stitch.ts (PNG output through canvas.toBuffer('image/png')). Image sources use the shared Apexify image loading/preflight path and may be a local/remote string source or Buffer.

Both helpers bound source loading by the central batch-concurrency limit and validate final canvas dimensions before allocation.


stitchImages(images, options?)

StitchOptions (lib-next/types/batch.ts)

FieldDefaultBehaviour
directionhorizontalhorizontal | vertical | grid.
overlap0Pixels subtracted between neighbours for horizontal/vertical stitching. Grid rejects non-zero overlap.
spacing0Extra pixels inserted between tiles.
blendfalseWith a real overlap, the overlap region is redrawn with multiply and globalAlpha = 0.5; non-overlap pixels are not darkened.

Layout rules

  • Horizontal / vertical: canvas spans the sum of tile extents minus overlap plus spacing; the orthogonal extent is the maximum input edge.
  • Grid: cols = ceil(sqrt(n)), rows = ceil(n / cols); every cell uses the maximum input width/height. Inputs keep their intrinsic dimensions and are anchored to the top-left of each cell.
  • A combination of overlap/spacing that would produce a non-positive output dimension is rejected before canvas allocation.
SOURCEtypescript
typescript
Studio
const strip = await painter.image.stitchImages(['./a.png', './b.png'], {  direction: 'horizontal',  spacing: 8,}); const sheet = await painter.image.stitchImages(urls, { direction: 'grid' });

createCollage(images, layout)

Images argument

SOURCEtypescript
typescript
Studio
Array<{ source: string | Buffer; width?: number; height?: number }>;

Optional width / height control the draw size and default to the decoded raster dimensions. Positive integer dimensions are required when supplied.

CollageLayout

FieldDefaultNotes
typerequired by the public typegrid | masonry | carousel. The old misleading custom value is no longer accepted because it never had a real placement algorithm.
columns / rows3 / 3Grid uses columns; declared rows is a minimum and automatically expands so inputs are never silently dropped. Masonry uses columns.
spacing10Gap in pixels between cells/tiles.
background#ffffffFilled before drawing.
borderRadius0Uses ctx.roundRect + clip for each tile, clamped to half the tile width/height.

Layout behaviour

typeAlgorithm
gridUniform cell max(width) × max(height), row-major. If rows is too small for all inputs, Apexify expands the row count.
masonryEach next image is placed in the currently shortest column; column heights include configured spacing.
carouselOne horizontal strip with vertical centering; widths are summed with spacing.
SOURCEtypescript
typescript
Studio
const board = await painter.image.createCollage(  [    { source: './photo-a.jpg', width: 320, height: 240 },    { source: './photo-b.jpg' },  ],  {    type: 'grid',    columns: 2,    rows: 2,    spacing: 12,    background: '#0f172a',    borderRadius: 8,  });

Next steps