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

Node / Raster Batch Output · guide

Resize, convert & effects

Current Apexify.js 6.0.0 documentation for Resize, convert & effects.

apexify.jsRuntime: nodeCURRENTSince 6.0.0

The raster helpers on painter.image now share the same image-source boundary used by canvas/image rendering. Supported sources are Buffer bytes, http(s): URLs, data:image/...;base64,... values, and filesystem paths. Image metadata is preflighted before decode against the configured source-byte, decoded-dimension, decoded-pixel, frame/page, and SVG-complexity limits. Remote inputs continue through the shared network policy rather than a helper-specific HTTP client.

This means resize, conversion, effects, color filtering, color analysis, masking, crop, and the other raster helpers no longer maintain separate ad-hoc filesystem/HTTP/canvas loaders.


resize(resizeOptions)

ResizeOptions:

FieldRole
imagePath**`string
sizePositive integer width / height. An omitted axis defaults to 500. The requested dimensions may enlarge the source.
maintainAspectRatiotrue uses Sharp inside/contain semantics; false uses fill and produces the exact requested dimensions.
qualityInteger 1–100 for the selected encoder.
outputFormatpng (default) or jpeg. The option is applied to the emitted bytes.

EXIF orientation is applied before fitting, so portrait/landscape sizing uses the effective displayed dimensions rather than unrotated metadata.

SOURCEtypescript
typescript
Studio
import { ApexPainter } from 'apexify.js';import fs from 'node:fs'; const painter = new ApexPainter(); const contained = await painter.image.resize({  imagePath: './uploads/poster.png',  size: { width: 1280, height: 720 },  maintainAspectRatio: true,  outputFormat: 'jpeg',  quality: 88,}); const exact = await painter.image.resize({  imagePath: fs.readFileSync('./raw.webp'),  size: { width: 512, height: 512 },  maintainAspectRatio: false,  outputFormat: 'png',}); const fromUrl = await painter.image.resize({  imagePath: 'https://cdn.example.com/assets/banner.jpg',  size: { width: 1200, height: 630 },  maintainAspectRatio: true,}); const dataUrl = `data:image/png;base64,${fs.readFileSync('./icon.png').toString('base64')}`;const fromDataUrl = await painter.image.resize({  imagePath: dataUrl,  size: { width: 64, height: 64 },});

Invalid, fractional, zero, over-limit, or otherwise unsafe target dimensions reject before the expensive resize work begins.


imgConverter(source, newExtension)

source is string | Buffer and uses the same metadata/decode preflight as resize.

Accepted extension names are jpeg, jpg, png, webp, tiff, gif, avif, heif, raw, jp2, and jxl. jpg is normalized to jpeg. Actual codec availability can still depend on the Sharp/libvips build used by the platform.

SOURCEtypescript
typescript
Studio
const webpBuf = await painter.image.imgConverter('./exports/frame.png', 'webp');const jpegFromBytes = await painter.image.imgConverter(fs.readFileSync('./frame.png'), 'jpg');const pngFromRemote = await painter.image.imgConverter('https://cdn.example.com/x.jpg', 'png');

effects(source, filters)

effects resolves and caches the decoded source through the shared image pipeline, then applies the requested filter stack.

Legacy effect names remain supported for compatibility:

  • flip, rotate, brightness, contrast, invert, greyscale, sepia, blur, posterize, pixelate

The typed raster-filter pipeline is also supported:

  • grayscale, gaussianBlur, motionBlur, radialBlur, sharpen, noise, grain, edgeDetection, emboss, saturation, hueShift

Noise/grain operations are deterministic for reproducible renders, and the legacy blur path delegates to the shared native filter implementation instead of running a quadratic JavaScript blur loop.

SOURCEtypescript
typescript
Studio
const painter = new ApexPainter(); const toned = await painter.image.effects('./raw.jpg', [  { type: 'blur', radius: 1.2 },  { type: 'brightness', value: 0.12 },  { type: 'contrast', value: 8 },]); const detailed = await painter.image.effects('./hero.png', [  { type: 'sharpen', intensity: 0.35 },  { type: 'grain', intensity: 0.05 },]);

Explicit zero values are preserved; for example, zero intensity is a no-op instead of being replaced with a default intensity.


colorsFilter(source, filterColor, opacity?)

Tint / wash using a CSS color string or GradientConfig. opacity is 0–1, and explicit 0 remains fully transparent.

SOURCEtypescript
typescript
Studio
const tinted = await painter.image.colorsFilter('./bw.png', '#6366f1', 0.35); const vignetteTint = await painter.image.colorsFilter('./scene.jpg', {  type: 'radial',  startX: 400,  startY: 300,  endX: 400,  endY: 300,  startRadius: 0,  endRadius: 420,  colors: [    { stop: 0, color: 'rgba(0,0,0,0)' },    { stop: 1, color: 'rgba(15,23,42,0.65)' },  ],});

Gradient stops must be finite, monotonic, and in 0–1. Linear/radial gradients support repeat: 'repeat' | 'reflect' | 'no-repeat'; reflect mirrors each adjacent period rather than merely repeating it.


colorAnalysis(source)

Returns a bounded dominant-color list in the historical { color, frequency }[] shape.

For large images the implementation metadata-preflights first, downsamples to at most 160×160, quantizes nearby RGB values, and returns at most 16 dominant colors. Transparent pixels are not emitted as colors; frequency keeps the compatibility denominator based on all sampled pixels.

SOURCEtypescript
typescript
Studio
const paletteHints = await painter.image.colorAnalysis('./brand-asset.png');console.log(paletteHints.slice(0, 8));

colorsRemover(source, colorToRemove)

Removes one exact RGB color. Each channel is 0–255.

SOURCEtypescript
typescript
Studio
const keyFilled = await painter.image.colorsRemover('./sprite.png', {  red: 255,  green: 0,  blue: 255,});

removeBackground(imageURL, apiKey)

Calls the remove.bg service through Apexify.js's bounded remote transport. The API key and remote service quotas remain external concerns.

SOURCEtypescript
typescript
Studio
const cutout = await painter.image.removeBackground(  'https://cdn.example.com/uploads/portrait.jpg',  process.env.REMOVAL_API_KEY!);

validHex(hexColor)

Validates #RRGGBB and throws for invalid input.

SOURCEtypescript
typescript
Studio
painter.image.validHex('#0ea5e9');

Next steps