Node / Raster Batch Output · guide
Stitch & collage
Current Apexify.js 6.0.0 documentation for Stitch & collage.
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)
| Field | Default | Behaviour |
|---|---|---|
direction | horizontal | horizontal | vertical | grid. |
overlap | 0 | Pixels subtracted between neighbours for horizontal/vertical stitching. Grid rejects non-zero overlap. |
spacing | 0 | Extra pixels inserted between tiles. |
blend | false | With 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.
createCollage(images, layout)
Images argument
Optional width / height control the draw size and default to the decoded raster dimensions. Positive integer dimensions are required when supplied.
CollageLayout
| Field | Default | Notes |
|---|---|---|
type | required by the public type | grid | masonry | carousel. The old misleading custom value is no longer accepted because it never had a real placement algorithm. |
columns / rows | 3 / 3 | Grid uses columns; declared rows is a minimum and automatically expands so inputs are never silently dropped. Masonry uses columns. |
spacing | 10 | Gap in pixels between cells/tiles. |
background | #ffffff | Filled before drawing. |
borderRadius | 0 | Uses ctx.roundRect + clip for each tile, clamped to half the tile width/height. |
Layout behaviour
type | Algorithm |
|---|---|
grid | Uniform cell max(width) × max(height), row-major. If rows is too small for all inputs, Apexify expands the row count. |
masonry | Each next image is placed in the currently shortest column; column heights include configured spacing. |
carousel | One horizontal strip with vertical centering; widths are summed with spacing. |