imgkit
v2.2.0
Published
High-performance image processing for Bun and Node.js - resize, convert, compress with HEIC, WebP, AVIF, PNG, JPEG support
Maintainers
Readme
imgkit
High-performance image processing for Bun and Node.js
Built with Rust and napi-rs for maximum speed
Documentation · API Reference · Examples · Changelog
Highlights
Performance
- 950x faster metadata extraction
- 1.9x faster thumbnail generation
- 2.6x faster concurrent operations
- SIMD-accelerated JPEG codec
- Zero-copy cropping & buffer handling
Features
- Fast Thumbnails (shrink-on-load)
- Native HEIC/HEIF support
- Smart Crop (content-aware)
- Dominant Colors (UI theming)
- ThumbHash & BlurHash placeholders
- Perceptual Hashing (pHash/dHash)
- ML Tensor Conversion (SIMD)
- EXIF metadata read/write
- Timeout & AbortSignal support
Installation
bun add imgkit # Bun
npm install imgkit # npm
yarn add imgkit # Yarn
pnpm add imgkit # pnpmQuick Start
import { 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 });API
| 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 & Platforms
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)
Development
git clone https://github.com/nexus-aissam/imgkit.git && cd imgkit
bun install && bun run build && bun run build:ts && bun test