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

Node / Raster Batch Output · guide

Blend, mask, crop & gradient

Current Apexify.js 6.0.0 documentation for Blend, mask, crop & gradient.

apexify.jsRuntime: nodeCURRENTSince 6.0.0

These painter.image helpers share the same bounded image-source/decode pipeline used by canvas rendering. Local files, bytes, data URLs, and remote images are resolved through one policy; metadata limits and SVG restrictions are applied before expensive raster work.

SOURCEtypescript
typescript
Studio
import { ApexPainter } from 'apexify.js'; const painter = new ApexPainter();

blend(layers, baseImageBuffer, defaultBlendMode?)

Stacks ImageBlendLayer entries over a baseImageBuffer. Layer order is deterministic: array index 0 is composited first, later entries are painted above it. Optional layer opacity preserves explicit 0.

SOURCEtypescript
typescript
Studio
import fs from 'node:fs'; const base = fs.readFileSync('./base-photo.jpg');const blended = await painter.image.blend([  {    image: './overlay-flare.png',    blendMode: 'screen',    position: { x: 0, y: 0 },    opacity: 0.75,  },  {    image: './grain.png',    blendMode: 'overlay',    opacity: 0.25,  },], base, 'source-over');

cropImage(options)

cropImage uses the shared source validator/cache and then applies either an axis-aligned inner crop or an outer punch-out path.

Coordinate rules

  • At least 3 coordinate rows are required.
  • Every from.x, from.y, to.x, and to.y must be finite and non-negative.
  • 0 is valid for both axes.
  • Coordinates that exceed the decoded source width/height reject instead of relying on backend clipping.
  • A degenerate inner crop with zero width or height rejects.

crop: 'inner'

Every from/to point contributes to the minimum/maximum X/Y values. Those extrema form the rectangular output region. Optional numeric radius rounds the crop rectangle; radius: 'circular' clips it to the largest centered circle that fits.

crop: 'outer'

The source dimensions are preserved. The coordinate path is filled using destination-out, producing a transparent hole while leaving pixels outside the path untouched. tension influences the Bézier control points.

SOURCEtypescript
typescript
Studio
const innerCrop = await painter.image.cropImage({  imageSource: './poster.jpg',  crop: 'inner',  radius: 16,  coordinates: [    { from: { x: 0, y: 0 }, to: { x: 520, y: 0 } },    { from: { x: 520, y: 0 }, to: { x: 520, y: 380 } },    { from: { x: 520, y: 380 }, to: { x: 0, y: 380 } },    { from: { x: 0, y: 380 }, to: { x: 0, y: 0 } },  ],}); const outerCrop = await painter.image.cropImage({  imageSource: './texture.png',  crop: 'outer',  coordinates: [    { from: { x: 0, y: 0 }, to: { x: 400, y: 0 }, tension: 0 },    { from: { x: 400, y: 0 }, to: { x: 200, y: 300 }, tension: 0.15 },    { from: { x: 200, y: 300 }, to: { x: 0, y: 0 }, tension: 0 },  ],});

masking(source, maskSource, options?)

Both the source and mask pass through the shared image-source policy and decoded-image cache. The output uses the source dimensions; the mask is fitted to those dimensions before mask values are applied.

MaskOptions:

FieldMeaning
typealpha (default), grayscale, or color
thresholdGrayscale cutoff 0–255
colorKeyRequired with type: 'color', formatted as #RRGGBB
invertInverts the resulting mask alpha
SOURCEtypescript
typescript
Studio
const alphaMasked = await painter.image.masking('./photo.jpg', './soft-mask.png', {  type: 'alpha',}); const thresholdMask = await painter.image.masking('./photo.jpg', './heightmap.png', {  type: 'grayscale',  threshold: 128,}); const keyed = await painter.image.masking('./photo.jpg', './greenscreen-solid.png', {  type: 'color',  colorKey: '#00ff00',  invert: false,});

Invalid mask modes/options use Apexify.js structured input/decode errors rather than generic helper-specific exceptions.


gradientBlend(source, options)

BlendOptions supports linear, radial, and conic gradients plus the documented blend modes. Gradient stop validation is shared with the rest of the rendering pipeline, so stops must be finite, monotonic, and within 0–1.

SOURCEtypescript
typescript
Studio
const graded = await painter.image.gradientBlend('./hero.jpg', {  type: 'linear',  angle: 120,  colors: [    { stop: 0, color: 'rgba(59,130,246,0)' },    { stop: 1, color: 'rgba(59,130,246,0.45)' },  ],  blendMode: 'multiply',}); const vignette = await painter.image.gradientBlend('./still.jpg', {  type: 'radial',  colors: [    { stop: 0.35, color: 'rgba(2,6,23,0)' },    { stop: 1, color: 'rgba(2,6,23,0.55)' },  ],  blendMode: 'overlay',});

Composition mindset

Use these helpers when you need a transformed raster before or between larger canvas/scene composition steps. Because the source resolver, decoder limits, cache, and structured validation are shared, the same safety/resource behavior applies whether the image is used directly or later placed into a scene.


Next steps