Skip to main content

Install

@napi-rs/canvas is a peer dependency — it provides the Skia-backed canvas used for pixel analysis on Node. Zero system dependencies.

Why pre-compute?

Logo Soup normally runs client-side on a <canvas>. That’s fine for most cases, but sometimes you want to skip the client-side pixel scanning entirely:
  • Static sites / build-time optimization — measure logos once at build time, ship the results as JSON
  • SSR / API routes — compute measurements on the server so the client renders instantly with no layout shift
  • Large logo sets — offload the work from the browser for 50+ logos
The Node adapter runs the exact same measurement pipeline as the browser (same downsampling, same single-pass pixel scan, same normalization math), just using @napi-rs/canvas instead of an HTMLCanvasElement.

measureImage

Measure a single image. Accepts a file path, URL, or Buffer.

Parameters

string | Buffer
required
A file path, HTTP URL, or Buffer containing image data. Supports PNG, JPEG, SVG, WebP, and any format @napi-rs/canvas can decode.
MeasureOptions

Returns

Promise<MeasurementResult> — the same type returned by the browser engine’s content detection:

measureImages

Measure multiple images in parallel. Returns results in the same order as the input array.

Build-time workflow

The typical workflow is: measure on the server, serialize the results, and use them on the client to skip all canvas work.

1. Measure at build time

2. Use on the client

The client never loads a canvas, never scans pixels, and never waits for image loads before knowing the layout dimensions. The createNormalizedLogo and getVisualCenterTransform functions are pure math that work anywhere.

API route example

The same approach works at request time in a server framework:

Re-exported utilities

The Node adapter re-exports the pure math functions you need to go from MeasurementResult to rendered output, so you don’t need to import from the core entry point:

Differences from the browser engine

The measurement results are identical. Both paths downsample to ~2,048 pixels and run the same single-pass scan.