High-performance image processing for Bun and Node.js
Built with Rust and napi-rs for maximum speed
|
|
bun add imgkit # Bun
npm install imgkit # npm
yarn add imgkit # Yarn
pnpm add imgkit # pnpmimport { resize, metadata, smartCrop, transform, thumbhash, toTensor } from 'imgkit';
const buf = Buffer.from(await Bun.file('photo.jpg').arrayBuffer());
const info = await metadata(buf); // Ultra-fast metadata
const resized = await resize(buf, { width: 200 }); // Resize
const thumb = await smartCrop(buf, { aspectRatio: '1:1' }); // Content-aware crop
const { dataUrl } = await thumbhash(buf); // Placeholder image
const webp = await transform(buf, { // Full pipeline
crop: { aspectRatio: '16:9' }, resize: { width: 1280 },
output: { format: 'webp', webp: { quality: 85 } }
});
const tensor = await toTensor(buf, { // ML-ready tensor
width: 224, height: 224, normalization: 'Imagenet', layout: 'Chw'
});
// Timeout & cancellation (all async functions)
const safe = await resize(buf, { width: 800 }, { timeoutMs: 5000 });
const ac = new AbortController();
await resize(buf, { width: 800 }, { signal: ac.signal });| Function | Description | Async | Sync |
|---|---|---|---|
metadata() |
Image dimensions, format, color info | ✅ | ✅ |
resize() |
Resize with multiple algorithms | ✅ | ✅ |
crop() |
Crop region (zero-copy) | ✅ | ✅ |
smartCrop() |
Content-aware crop | ✅ | ✅ |
dominantColors() |
Extract colors for UI theming | ✅ | ✅ |
thumbnail() |
Fast thumbnail (shrink-on-load) | ✅ | ✅ |
transform() |
Multi-operation pipeline | ✅ | ✅ |
toJpeg() / toPng() / toWebp() |
Format conversion | ✅ | ✅ |
blurhash() / thumbhash() |
Image placeholders | ✅ | ✅ |
toTensor() |
ML tensor (SIMD-accelerated) | ✅ | ✅ |
imageHash() / imageHashDistance() |
Perceptual hashing | ✅ | ✅ |
writeExif() / stripExif() |
EXIF metadata | ✅ | ✅ |
All async functions support { timeoutMs?, signal? } for timeout & cancellation. All have sync variants (resizeSync(), etc.).
Formats: JPEG (TurboJPEG/SIMD), PNG, WebP, GIF, BMP, TIFF (read), HEIC/AVIF (macOS ARM64)
Platforms: macOS (ARM64, x64) · Linux (x64 glibc/musl, ARM64) · Windows (x64, ARM64)
git clone https://github.com/nexus-aissam/imgkit.git && cd imgkit
bun install && bun run build && bun run build:ts && bun test