@suaveplan/image - Universal image metadata extraction, format detection, resize math, crop validation, and transform pipeline planning
Universal image metadata extraction, format detection, resize math, crop validation, and transform pipeline planning. Zero browser or Node dependencies — runs in Bun, Node, and browsers alike. Provides ImageProcessor for planning image transforms, PipelineBuilder for fluent composition, and header-based dimension parsers for JPEG, PNG, WebP, GIF, and AVIF.
Documentation tree
- error-codes —
error-codes.tsdeclares the canonical error-code registry for@suaveplan/image. Every failure mode that the image p…- error-codes —
error-codes.tsdeclares the canonical error-code registry for@suaveplan/image. Every failure mode that the image p…
- error-codes —
- errors —
errors.tsprovides the typed error hierarchy for@suaveplan/image.ImageErrorextendsSuaveplanErrorso that ca…- errors —
errors.tsprovides the typed error hierarchy for@suaveplan/image.ImageErrorextendsSuaveplanErrorso that ca…
- errors —
- dimensions —
dimensions.tsextracts width and height from raw image headers for the four supported raster formats: PNG, JPEG, GIF,…- dimensions —
dimensions.tsextracts width and height from raw image headers for the four supported raster formats: PNG, JPEG, GIF,…
- dimensions —
- instruments —
instruments.tslazily initialises the OpenTelemetry counters and histograms used byImageProcessor. Each instrument…- instruments —
instruments.tslazily initialises the OpenTelemetry counters and histograms used byImageProcessor. Each instrument…
- instruments —
- pipeline-builder —
pipeline-builder.tsimplements a fluent, chainable API for constructing image transform pipelines. Each method append…- pipeline-builder —
pipeline-builder.tsimplements a fluent, chainable API for constructing image transform pipelines. Each method append…
- pipeline-builder —
- processor —
processor.tsis the orchestration layer of@suaveplan/image.ImageProcessoraccepts aUint8Arrayof image bytes…- processor —
processor.tsis the orchestration layer of@suaveplan/image.ImageProcessoraccepts aUint8Arrayof image bytes…
- processor —
- image-detect —
image-detect.tsprovides fast, deterministic format detection from raw binary headers. It inspects the first bytes of…- image-detect —
image-detect.tsprovides fast, deterministic format detection from raw binary headers. It inspects the first bytes of…
- image-detect —
- image-types —
image-types.tsis the universal type system and pure-function toolkit for image metadata. It defines Zod schemas…- image-types —
image-types.tsis the universal type system and pure-function toolkit for image metadata. It defines Zod schemas…
- image-types —
Installation
bun add @suaveplan/image
Quick Start
import { ImageProcessor } from "@suaveplan/image";
const proc = new ImageProcessor({ maxPixels: 50_000_000 });
const meta = proc.extractMetadata(imageBytes);
console.log(`${meta.format} ${meta.width}x${meta.height}`);
const result = proc.planTransform(meta, {
operations: [
{ type: "resize", options: { width: 400 } },
{ type: "format", format: "webp" },
],
});
Modules
src/processor/processor/processor.md—ImageProcessorandPipelineBuildersrc/processor/instruments/instruments.md— OpenTelemetry instrumentation helperssrc/processor/dimensions/dimensions.md— Header dimension parsers for JPEG, PNG, WebP, GIF, AVIFsrc/processor/pipeline-builder/pipeline-builder.md— Fluent transform pipeline buildersrc/types/image-types/image-types.md— TypeScript interfaces and Zod schemassrc/types/image-detect/image-detect.md— Format detection types and constantssrc/errors/errors.md—ImageErrorhierarchy and typed factoriessrc/error-codes/error-codes.md— StableIMAGE.*error code registry