bun-image-turbo 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +247 -241
- package/package.json +53 -53
package/README.md
CHANGED
|
@@ -1,332 +1,323 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
| **
|
|
50
|
-
| **
|
|
51
|
-
| **
|
|
52
|
-
| **
|
|
53
|
-
| **
|
|
54
|
-
| **
|
|
55
|
-
| **
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
| Operation | Time | Notes |
|
|
62
|
-
|-----------|-----:|:------|
|
|
63
|
-
| **HEIC Metadata** | 0.1ms | Instant metadata extraction |
|
|
64
|
-
| **HEIC → JPEG** | 169ms | Full quality conversion |
|
|
65
|
-
| **HEIC → 800px JPEG** | 138ms | Optimized shrink-on-decode |
|
|
66
|
-
| **HEIC → 200px thumbnail** | 137ms | Fast thumbnail generation |
|
|
67
|
-
| **HEIC → WebP** | 798ms | Modern format conversion |
|
|
68
|
-
| **HEIC Blurhash** | 301ms | Placeholder generation |
|
|
69
|
-
|
|
70
|
-
> sharp does **NOT** support HEIC/HEIF files!
|
|
71
|
-
|
|
72
|
-
### Key Strengths
|
|
73
|
-
|
|
74
|
-
- **950x faster** WebP metadata extraction
|
|
75
|
-
- **38x faster** JPEG metadata (header-only parsing)
|
|
76
|
-
- **2.6x faster** under concurrent load (server workloads)
|
|
77
|
-
- **1.6x faster** transform pipelines (resize + rotate + grayscale)
|
|
78
|
-
- **Native HEIC/HEIF support** - Read iPhone photos directly
|
|
79
|
-
- **Shrink-on-decode** optimization for JPEG and HEIC
|
|
80
|
-
- Built-in **Blurhash** generation
|
|
81
|
-
- Zero-copy buffer handling with Rust
|
|
82
|
-
|
|
83
|
-
> Run benchmarks yourself: `bun run benchmarks/final_comparison.ts`
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
⚡ bun-image-turbo
|
|
3
|
+
</h1>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<strong>High-performance image processing for Bun and Node.js</strong><br>
|
|
7
|
+
Built with Rust and napi-rs for maximum speed
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a href="https://www.npmjs.com/package/bun-image-turbo"><img src="https://badge.fury.io/js/bun-image-turbo.svg" alt="npm version"></a>
|
|
12
|
+
<a href="https://github.com/nexus-aissam/bun-image-turbo/actions/workflows/build.yml"><img src="https://github.com/nexus-aissam/bun-image-turbo/actions/workflows/build.yml/badge.svg" alt="Build & Publish"></a>
|
|
13
|
+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
|
|
14
|
+
<a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-5.0+-blue.svg" alt="TypeScript"></a>
|
|
15
|
+
<a href="https://nodejs.org/"><img src="https://img.shields.io/badge/Node.js-18+-green.svg" alt="Node.js"></a>
|
|
16
|
+
<a href="https://bun.sh/"><img src="https://img.shields.io/badge/Bun-1.0+-orange.svg" alt="Bun"></a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
<a href="https://nexus-aissam.github.io/bun-image-turbo/"><img src="https://img.shields.io/badge/📖_Documentation-Visit_Docs-blue?style=for-the-badge" alt="Documentation"></a>
|
|
21
|
+
<a href="https://nexus-aissam.github.io/bun-image-turbo/api/"><img src="https://img.shields.io/badge/📚_API-Reference-green?style=for-the-badge" alt="API Reference"></a>
|
|
22
|
+
<a href="https://www.npmjs.com/package/bun-image-turbo"><img src="https://img.shields.io/badge/📦_npm-Package-red?style=for-the-badge" alt="npm Package"></a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<p align="center">
|
|
26
|
+
<b>Up to 950x faster</b> than alternatives • <b>Native HEIC support</b> • <b>Zero-copy buffers</b> • <b>SIMD-accelerated</b>
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Why bun-image-turbo?
|
|
32
|
+
|
|
33
|
+
| vs sharp | Speedup | Why |
|
|
34
|
+
|----------|:-------:|-----|
|
|
35
|
+
| WebP Metadata | **950x** | Header-only parsing, no decode |
|
|
36
|
+
| JPEG Metadata | **38x** | Optimized marker extraction |
|
|
37
|
+
| 50 Concurrent Ops | **2.6x** | Rayon thread pool |
|
|
38
|
+
| Transform Pipeline | **1.6x** | Single-pass processing |
|
|
39
|
+
| HEIC Support | **Exclusive** | Only lib with native HEIC |
|
|
40
|
+
|
|
41
|
+
> **bun-image-turbo** is the fastest image processing library for JavaScript. Period.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Quick Links
|
|
46
|
+
|
|
47
|
+
| Resource | Link |
|
|
48
|
+
|----------|------|
|
|
49
|
+
| **Documentation** | [nexus-aissam.github.io/bun-image-turbo](https://nexus-aissam.github.io/bun-image-turbo/) |
|
|
50
|
+
| **API Reference** | [Full API Docs](https://nexus-aissam.github.io/bun-image-turbo/api/) |
|
|
51
|
+
| **Examples** | [Code Examples](https://nexus-aissam.github.io/bun-image-turbo/examples/) |
|
|
52
|
+
| **Getting Started** | [Installation Guide](https://nexus-aissam.github.io/bun-image-turbo/guide/) |
|
|
53
|
+
| **Architecture** | [Technical Deep Dive](https://nexus-aissam.github.io/bun-image-turbo/guide/architecture) |
|
|
54
|
+
| **Performance** | [Benchmarks & Optimization](https://nexus-aissam.github.io/bun-image-turbo/guide/performance) |
|
|
55
|
+
| **npm Package** | [npmjs.com/package/bun-image-turbo](https://www.npmjs.com/package/bun-image-turbo) |
|
|
56
|
+
| **GitHub** | [nexus-aissam/bun-image-turbo](https://github.com/nexus-aissam/bun-image-turbo) |
|
|
57
|
+
| **Changelog** | [Release Notes](https://nexus-aissam.github.io/bun-image-turbo/changelog) |
|
|
58
|
+
|
|
59
|
+
---
|
|
84
60
|
|
|
85
61
|
## Installation
|
|
86
62
|
|
|
87
63
|
```bash
|
|
88
|
-
#
|
|
64
|
+
# Bun (recommended)
|
|
89
65
|
bun add bun-image-turbo
|
|
90
66
|
|
|
91
|
-
#
|
|
67
|
+
# npm
|
|
92
68
|
npm install bun-image-turbo
|
|
93
69
|
|
|
94
|
-
#
|
|
70
|
+
# yarn
|
|
95
71
|
yarn add bun-image-turbo
|
|
96
72
|
|
|
97
|
-
#
|
|
73
|
+
# pnpm
|
|
98
74
|
pnpm add bun-image-turbo
|
|
99
75
|
```
|
|
100
76
|
|
|
77
|
+
Prebuilt binaries are available for **all major platforms** - no compilation needed.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
101
81
|
## Quick Start
|
|
102
82
|
|
|
103
83
|
```typescript
|
|
104
|
-
import { resize,
|
|
84
|
+
import { metadata, resize, transform, toWebp, blurhash } from 'bun-image-turbo';
|
|
105
85
|
|
|
106
86
|
// Read image
|
|
107
|
-
const
|
|
108
|
-
const buffer = Buffer.from(input);
|
|
87
|
+
const buffer = Buffer.from(await Bun.file('photo.jpg').arrayBuffer());
|
|
109
88
|
|
|
110
|
-
// Get metadata
|
|
89
|
+
// Get metadata (ultra-fast, header-only)
|
|
111
90
|
const info = await metadata(buffer);
|
|
112
91
|
console.log(`${info.width}x${info.height} ${info.format}`);
|
|
113
92
|
|
|
114
|
-
// Resize
|
|
115
|
-
const
|
|
93
|
+
// Resize with shrink-on-decode optimization
|
|
94
|
+
const thumbnail = await resize(buffer, { width: 200 });
|
|
116
95
|
|
|
117
|
-
// Convert to WebP
|
|
96
|
+
// Convert to WebP (50-80% smaller than JPEG)
|
|
118
97
|
const webp = await toWebp(buffer, { quality: 85 });
|
|
119
98
|
|
|
120
|
-
//
|
|
99
|
+
// Full transform pipeline
|
|
121
100
|
const result = await transform(buffer, {
|
|
122
|
-
resize: { width:
|
|
101
|
+
resize: { width: 800, height: 600, fit: 'cover' },
|
|
123
102
|
rotate: 90,
|
|
124
103
|
grayscale: true,
|
|
125
|
-
|
|
104
|
+
sharpen: 10,
|
|
105
|
+
output: { format: 'webp', webp: { quality: 85 } }
|
|
126
106
|
});
|
|
127
107
|
|
|
108
|
+
// Generate blurhash placeholder
|
|
109
|
+
const { hash } = await blurhash(buffer, 4, 3);
|
|
110
|
+
|
|
128
111
|
// Save result
|
|
129
112
|
await Bun.write('output.webp', result);
|
|
130
|
-
|
|
131
|
-
// Convert HEIC (iPhone photo) to JPEG
|
|
132
|
-
const heicInput = await Bun.file('photo.heic').arrayBuffer();
|
|
133
|
-
const jpeg = await toJpeg(Buffer.from(heicInput), { quality: 90 });
|
|
134
|
-
await Bun.write('photo.jpg', jpeg);
|
|
135
113
|
```
|
|
136
114
|
|
|
137
|
-
|
|
115
|
+
**[See more examples →](https://nexus-aissam.github.io/bun-image-turbo/examples/)**
|
|
138
116
|
|
|
139
|
-
|
|
117
|
+
---
|
|
140
118
|
|
|
141
|
-
|
|
119
|
+
## Benchmarks
|
|
142
120
|
|
|
143
|
-
|
|
144
|
-
const info = await metadata(imageBuffer);
|
|
145
|
-
// { width: 1920, height: 1080, format: 'jpeg', hasAlpha: false, ... }
|
|
146
|
-
```
|
|
121
|
+
Tested on Apple M1 Pro with Bun 1.3.3 (compared to sharp v0.34.5):
|
|
147
122
|
|
|
148
|
-
###
|
|
123
|
+
### Metadata Extraction
|
|
149
124
|
|
|
150
|
-
|
|
125
|
+
| Operation | bun-image-turbo | sharp | Speedup |
|
|
126
|
+
|-----------|---------------:|------:|:-------:|
|
|
127
|
+
| WebP Metadata | **0.004ms** | 3.4ms | **950x** |
|
|
128
|
+
| JPEG Metadata | **0.003ms** | 0.1ms | **38x** |
|
|
129
|
+
| PNG Metadata | **0.002ms** | 0.08ms | **40x** |
|
|
151
130
|
|
|
152
|
-
|
|
153
|
-
// Resize by width (maintains aspect ratio)
|
|
154
|
-
const resized = await resize(imageBuffer, { width: 800 });
|
|
155
|
-
|
|
156
|
-
// Resize by height
|
|
157
|
-
const resized = await resize(imageBuffer, { height: 600 });
|
|
158
|
-
|
|
159
|
-
// Resize with specific dimensions
|
|
160
|
-
const resized = await resize(imageBuffer, {
|
|
161
|
-
width: 800,
|
|
162
|
-
height: 600,
|
|
163
|
-
fit: 'cover', // 'cover' | 'contain' | 'fill' | 'inside' | 'outside'
|
|
164
|
-
filter: 'lanczos3' // 'nearest' | 'bilinear' | 'catmullRom' | 'mitchell' | 'lanczos3'
|
|
165
|
-
});
|
|
166
|
-
```
|
|
131
|
+
### Image Processing
|
|
167
132
|
|
|
168
|
-
|
|
133
|
+
| Operation | bun-image-turbo | sharp | Speedup |
|
|
134
|
+
|-----------|---------------:|------:|:-------:|
|
|
135
|
+
| 50 Concurrent Ops | **62ms** | 160ms | **2.6x** |
|
|
136
|
+
| Transform Pipeline | **12.2ms** | 19.1ms | **1.6x** |
|
|
137
|
+
| 1MB JPEG → 800px | **12.6ms** | 20.3ms | **1.6x** |
|
|
138
|
+
| Thumbnail (200px) | **8.8ms** | 10.7ms | **1.2x** |
|
|
169
139
|
|
|
170
|
-
|
|
140
|
+
### HEIC Support (Exclusive)
|
|
171
141
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
142
|
+
| Operation | Time | Notes |
|
|
143
|
+
|-----------|-----:|:------|
|
|
144
|
+
| HEIC Metadata | **0.1ms** | Header-only parsing |
|
|
145
|
+
| HEIC → JPEG | **169ms** | Full quality conversion |
|
|
146
|
+
| HEIC → 800px | **138ms** | Shrink-on-decode |
|
|
147
|
+
| HEIC → Thumbnail | **137ms** | Fast 200px generation |
|
|
175
148
|
|
|
176
|
-
|
|
149
|
+
> **sharp does NOT support HEIC/HEIF files!** bun-image-turbo is the only high-performance library with native HEIC support.
|
|
177
150
|
|
|
178
|
-
|
|
151
|
+
**[Full benchmark details →](https://nexus-aissam.github.io/bun-image-turbo/guide/performance)**
|
|
179
152
|
|
|
180
|
-
|
|
181
|
-
const png = await toPng(imageBuffer, { compression: 6 });
|
|
182
|
-
```
|
|
153
|
+
---
|
|
183
154
|
|
|
184
|
-
|
|
155
|
+
## Technology Stack
|
|
185
156
|
|
|
186
|
-
|
|
157
|
+
| Component | Technology | Benefit |
|
|
158
|
+
|-----------|------------|---------|
|
|
159
|
+
| **JPEG Codec** | TurboJPEG (libjpeg-turbo) | SIMD acceleration (SSE2/AVX2/NEON) |
|
|
160
|
+
| **Resize Engine** | fast_image_resize + Rayon | Multi-threaded with adaptive algorithms |
|
|
161
|
+
| **WebP Codec** | libwebp bindings | Google's optimized encoder/decoder |
|
|
162
|
+
| **HEIC Decoder** | libheif-rs | Native Apple format support |
|
|
163
|
+
| **Node Bindings** | napi-rs | Zero-copy buffer handling |
|
|
187
164
|
|
|
188
|
-
|
|
189
|
-
// Lossy WebP
|
|
190
|
-
const webp = await toWebp(imageBuffer, { quality: 80 });
|
|
165
|
+
**[Architecture deep dive →](https://nexus-aissam.github.io/bun-image-turbo/guide/architecture)**
|
|
191
166
|
|
|
192
|
-
|
|
193
|
-
const lossless = await toWebp(imageBuffer, { lossless: true });
|
|
194
|
-
```
|
|
167
|
+
---
|
|
195
168
|
|
|
196
|
-
|
|
169
|
+
## Features
|
|
197
170
|
|
|
198
|
-
|
|
171
|
+
- **TurboJPEG with SIMD** - 2-6x faster JPEG encoding/decoding via libjpeg-turbo
|
|
172
|
+
- **Shrink-on-Decode** - Decode JPEG/HEIC at reduced resolution for faster thumbnails
|
|
173
|
+
- **Adaptive Algorithms** - Auto-selects optimal resize filter based on scale factor
|
|
174
|
+
- **Native HEIC Support** - The only high-performance library with HEIC/HEIF decoding
|
|
175
|
+
- **Blurhash Generation** - Built-in compact placeholder generation
|
|
176
|
+
- **Multi-Step Resize** - Progressive halving for large scale reductions
|
|
177
|
+
- **Async & Sync APIs** - Both async and sync versions available
|
|
178
|
+
- **TypeScript First** - Full TypeScript support with strict types
|
|
179
|
+
- **Cross-Platform** - macOS, Linux, Windows support
|
|
199
180
|
|
|
200
|
-
|
|
201
|
-
const result = await transform(imageBuffer, {
|
|
202
|
-
// Resize
|
|
203
|
-
resize: { width: 800, height: 600, fit: 'cover' },
|
|
181
|
+
---
|
|
204
182
|
|
|
205
|
-
|
|
206
|
-
rotate: 90, // 90, 180, or 270 degrees
|
|
207
|
-
flipH: true, // Flip horizontally
|
|
208
|
-
flipV: false, // Flip vertically
|
|
209
|
-
grayscale: true, // Convert to grayscale
|
|
210
|
-
blur: 5, // Blur radius (0-100)
|
|
211
|
-
sharpen: 10, // Sharpen amount (0-100)
|
|
212
|
-
brightness: 10, // Brightness (-100 to 100)
|
|
213
|
-
contrast: 5, // Contrast (-100 to 100)
|
|
214
|
-
|
|
215
|
-
// Output format
|
|
216
|
-
output: {
|
|
217
|
-
format: 'webp',
|
|
218
|
-
webp: { quality: 85 }
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
```
|
|
183
|
+
## API Overview
|
|
222
184
|
|
|
223
|
-
|
|
185
|
+
| Function | Description | Docs |
|
|
186
|
+
|----------|-------------|------|
|
|
187
|
+
| `metadata()` | Get image info (ultra-fast) | [→](https://nexus-aissam.github.io/bun-image-turbo/api/metadata) |
|
|
188
|
+
| `resize()` | Resize image (outputs PNG) | [→](https://nexus-aissam.github.io/bun-image-turbo/api/resize) |
|
|
189
|
+
| `transform()` | Multi-operation pipeline | [→](https://nexus-aissam.github.io/bun-image-turbo/api/transform) |
|
|
190
|
+
| `toJpeg()` | Convert to JPEG | [→](https://nexus-aissam.github.io/bun-image-turbo/api/to-jpeg) |
|
|
191
|
+
| `toPng()` | Convert to PNG | [→](https://nexus-aissam.github.io/bun-image-turbo/api/to-png) |
|
|
192
|
+
| `toWebp()` | Convert to WebP | [→](https://nexus-aissam.github.io/bun-image-turbo/api/to-webp) |
|
|
193
|
+
| `blurhash()` | Generate placeholder hash | [→](https://nexus-aissam.github.io/bun-image-turbo/api/blurhash) |
|
|
224
194
|
|
|
225
|
-
|
|
195
|
+
All functions have sync variants (`metadataSync`, `resizeSync`, etc.)
|
|
226
196
|
|
|
227
|
-
|
|
228
|
-
const { hash, width, height } = await blurhash(imageBuffer, 4, 3);
|
|
229
|
-
console.log(hash); // "LEHV6nWB2yk8pyo0adR*.7kCMdnj"
|
|
230
|
-
```
|
|
197
|
+
**[Full API Reference →](https://nexus-aissam.github.io/bun-image-turbo/api/)**
|
|
231
198
|
|
|
232
|
-
|
|
199
|
+
---
|
|
233
200
|
|
|
234
|
-
|
|
201
|
+
## Supported Formats
|
|
235
202
|
|
|
236
|
-
|
|
237
|
-
|
|
203
|
+
| Format | Read | Write | Notes |
|
|
204
|
+
|--------|:----:|:-----:|-------|
|
|
205
|
+
| JPEG | ✅ | ✅ | TurboJPEG with SIMD |
|
|
206
|
+
| PNG | ✅ | ✅ | Adaptive compression |
|
|
207
|
+
| WebP | ✅ | ✅ | Lossy & lossless |
|
|
208
|
+
| HEIC/HEIF | ✅ | ❌ | macOS ARM64 only |
|
|
209
|
+
| AVIF | ✅ | ❌ | Via libheif |
|
|
210
|
+
| GIF | ✅ | ✅ | Animated support |
|
|
211
|
+
| BMP | ✅ | ✅ | Full support |
|
|
212
|
+
| TIFF | ✅ | ❌ | Multi-page support |
|
|
213
|
+
| ICO | ✅ | ❌ | Multi-size icons |
|
|
214
|
+
|
|
215
|
+
**[Format guide →](https://nexus-aissam.github.io/bun-image-turbo/guide/formats)**
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Platform Support
|
|
220
|
+
|
|
221
|
+
Prebuilt binaries are available for all major platforms:
|
|
222
|
+
|
|
223
|
+
| Platform | Architecture | Supported | HEIC |
|
|
224
|
+
|----------|--------------|:---------:|:----:|
|
|
225
|
+
| macOS | ARM64 (M1/M2/M3/M4/M5) | ✅ | ✅ |
|
|
226
|
+
| macOS | x64 (Intel) | ✅ | ❌ |
|
|
227
|
+
| Linux | x64 (glibc) | ✅ | ❌ |
|
|
228
|
+
| Linux | x64 (musl/Alpine) | ✅ | ❌ |
|
|
229
|
+
| Linux | ARM64 (glibc) | ✅ | ❌ |
|
|
230
|
+
| Windows | x64 | ✅ | ❌ |
|
|
231
|
+
| Windows | ARM64 | ✅ | ❌ |
|
|
232
|
+
|
|
233
|
+
> **Note:** HEIC/HEIF decoding is only available on macOS ARM64. All other formats work on all platforms.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Examples
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
cd examples
|
|
241
|
+
bun install
|
|
242
|
+
|
|
243
|
+
bun run basic # Core functionality
|
|
244
|
+
bun run heic # HEIC conversion (macOS ARM64)
|
|
245
|
+
bun run api # HTTP image server
|
|
246
|
+
bun run batch # Parallel batch processing
|
|
238
247
|
```
|
|
239
248
|
|
|
240
|
-
|
|
249
|
+
| Example | Description |
|
|
250
|
+
|---------|-------------|
|
|
251
|
+
| [basic-usage.ts](./examples/basic-usage.ts) | Metadata, resize, convert, transform |
|
|
252
|
+
| [heic-conversion.ts](./examples/heic-conversion.ts) | iPhone photo conversion |
|
|
253
|
+
| [api-endpoint.ts](./examples/api-endpoint.ts) | HTTP image processing server |
|
|
254
|
+
| [batch-processing.ts](./examples/batch-processing.ts) | Parallel multi-file processing |
|
|
241
255
|
|
|
242
|
-
|
|
256
|
+
**[All examples →](https://nexus-aissam.github.io/bun-image-turbo/examples/)**
|
|
243
257
|
|
|
244
|
-
|
|
245
|
-
|--------|------|---------|-------------|
|
|
246
|
-
| `width` | `number` | - | Target width (optional if height provided) |
|
|
247
|
-
| `height` | `number` | - | Target height (optional if width provided) |
|
|
248
|
-
| `filter` | `string` | `'lanczos3'` | Resize algorithm |
|
|
249
|
-
| `fit` | `string` | `'cover'` | How to fit the image |
|
|
258
|
+
---
|
|
250
259
|
|
|
251
|
-
|
|
260
|
+
## Documentation
|
|
252
261
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
- `mitchell` - Good for downscaling
|
|
257
|
-
- `lanczos3` - Highest quality, slower (default)
|
|
262
|
+
<table>
|
|
263
|
+
<tr>
|
|
264
|
+
<td width="50%">
|
|
258
265
|
|
|
259
|
-
###
|
|
266
|
+
### Online Documentation
|
|
260
267
|
|
|
261
|
-
|
|
262
|
-
- `contain` - Resize to fit within target (may have padding)
|
|
263
|
-
- `fill` - Resize to exact dimensions (may distort)
|
|
264
|
-
- `inside` - Resize only if larger than target
|
|
265
|
-
- `outside` - Resize only if smaller than target
|
|
268
|
+
Full documentation with examples, API reference, and guides:
|
|
266
269
|
|
|
267
|
-
|
|
270
|
+
**[nexus-aissam.github.io/bun-image-turbo](https://nexus-aissam.github.io/bun-image-turbo/)**
|
|
268
271
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
+
- [Getting Started](https://nexus-aissam.github.io/bun-image-turbo/guide/)
|
|
273
|
+
- [API Reference](https://nexus-aissam.github.io/bun-image-turbo/api/)
|
|
274
|
+
- [Examples](https://nexus-aissam.github.io/bun-image-turbo/examples/)
|
|
275
|
+
- [Architecture](https://nexus-aissam.github.io/bun-image-turbo/guide/architecture)
|
|
276
|
+
- [Performance](https://nexus-aissam.github.io/bun-image-turbo/guide/performance)
|
|
272
277
|
|
|
273
|
-
|
|
278
|
+
</td>
|
|
279
|
+
<td width="50%">
|
|
274
280
|
|
|
275
|
-
|
|
276
|
-
|--------|------|---------|-------------|
|
|
277
|
-
| `compression` | `number` | `6` | Compression level 0-9 |
|
|
281
|
+
### Offline Documentation
|
|
278
282
|
|
|
279
|
-
|
|
283
|
+
Documentation is also available in the [`docs/`](./docs/) folder:
|
|
280
284
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
| `lossless` | `boolean` | `false` | Use lossless compression |
|
|
285
|
+
- [Guide](./docs/guide/)
|
|
286
|
+
- [API](./docs/api/)
|
|
287
|
+
- [Examples](./docs/examples/)
|
|
285
288
|
|
|
286
|
-
|
|
289
|
+
View locally:
|
|
287
290
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
##
|
|
301
|
-
|
|
302
|
-
| Platform | Architecture | Support |
|
|
303
|
-
|----------|--------------|---------|
|
|
304
|
-
| macOS | ARM64 (M1/M2/M3) | Yes |
|
|
305
|
-
| macOS | x64 (Intel) | Yes |
|
|
306
|
-
| Linux | x64 (glibc) | Yes |
|
|
307
|
-
| Linux | x64 (musl/Alpine) | Yes |
|
|
308
|
-
| Linux | ARM64 (glibc) | Yes |
|
|
309
|
-
| Linux | ARM64 (musl) | Yes |
|
|
310
|
-
| Windows | x64 | Yes |
|
|
311
|
-
|
|
312
|
-
## Development
|
|
291
|
+
```bash
|
|
292
|
+
cd docs
|
|
293
|
+
bun install
|
|
294
|
+
bun run docs:dev
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
</td>
|
|
298
|
+
</tr>
|
|
299
|
+
</table>
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## Contributing
|
|
313
304
|
|
|
314
305
|
```bash
|
|
315
|
-
# Clone
|
|
306
|
+
# Clone
|
|
316
307
|
git clone https://github.com/nexus-aissam/bun-image-turbo.git
|
|
317
308
|
cd bun-image-turbo
|
|
318
309
|
|
|
319
310
|
# Install dependencies
|
|
320
311
|
bun install
|
|
321
312
|
|
|
322
|
-
# Build native module (requires Rust)
|
|
313
|
+
# Build native module (requires Rust 1.70+)
|
|
323
314
|
bun run build
|
|
324
315
|
|
|
325
316
|
# Build TypeScript
|
|
326
317
|
bun run build:ts
|
|
327
318
|
|
|
328
319
|
# Run tests
|
|
329
|
-
bun test
|
|
320
|
+
bun test test/
|
|
330
321
|
```
|
|
331
322
|
|
|
332
323
|
### Requirements
|
|
@@ -334,20 +325,35 @@ bun test
|
|
|
334
325
|
- Bun 1.0+ or Node.js 18+
|
|
335
326
|
- Rust 1.70+ (for building from source)
|
|
336
327
|
|
|
328
|
+
---
|
|
329
|
+
|
|
337
330
|
## License
|
|
338
331
|
|
|
339
332
|
MIT License - see [LICENSE](LICENSE) for details.
|
|
340
333
|
|
|
334
|
+
---
|
|
335
|
+
|
|
341
336
|
## Author
|
|
342
337
|
|
|
343
|
-
Aissam Irhir ([@nexus-aissam](https://github.com/nexus-aissam))
|
|
338
|
+
**Aissam Irhir** ([@nexus-aissam](https://github.com/nexus-aissam))
|
|
339
|
+
|
|
340
|
+
---
|
|
344
341
|
|
|
345
342
|
## Acknowledgments
|
|
346
343
|
|
|
347
344
|
- [turbojpeg](https://crates.io/crates/turbojpeg) - libjpeg-turbo bindings with SIMD
|
|
348
345
|
- [image](https://crates.io/crates/image) - Rust image processing library
|
|
349
|
-
- [fast_image_resize](https://crates.io/crates/fast_image_resize) - Fast image resizing
|
|
346
|
+
- [fast_image_resize](https://crates.io/crates/fast_image_resize) - Fast image resizing with Rayon
|
|
350
347
|
- [webp](https://crates.io/crates/webp) - WebP encoding/decoding
|
|
351
348
|
- [libheif-rs](https://crates.io/crates/libheif-rs) - HEIC/HEIF decoding via libheif
|
|
352
349
|
- [blurhash](https://crates.io/crates/blurhash) - Blurhash generation
|
|
353
350
|
- [napi-rs](https://napi.rs/) - Rust bindings for Node.js
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
<p align="center">
|
|
355
|
+
<a href="https://nexus-aissam.github.io/bun-image-turbo/">Documentation</a> •
|
|
356
|
+
<a href="https://nexus-aissam.github.io/bun-image-turbo/api/">API</a> •
|
|
357
|
+
<a href="https://www.npmjs.com/package/bun-image-turbo">npm</a> •
|
|
358
|
+
<a href="https://github.com/nexus-aissam/bun-image-turbo">GitHub</a>
|
|
359
|
+
</p>
|
package/package.json
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-image-turbo",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"
|
|
3
|
+
"version": "1.2.2",
|
|
4
|
+
"author": "Aissam Irhir <aissamirhir@gmail.com>",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/nexus-aissam/bun-image-turbo.git"
|
|
8
|
+
},
|
|
5
9
|
"main": "./dist/index.js",
|
|
6
10
|
"module": "./dist/index.mjs",
|
|
7
|
-
"
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@napi-rs/cli": "^2.18.4",
|
|
13
|
+
"@types/bun": "latest",
|
|
14
|
+
"sharp": "^0.34.5",
|
|
15
|
+
"tsup": "^8.4.0",
|
|
16
|
+
"typescript": "^5.9.0"
|
|
17
|
+
},
|
|
8
18
|
"exports": {
|
|
9
19
|
".": {
|
|
10
20
|
"import": {
|
|
@@ -17,35 +27,17 @@
|
|
|
17
27
|
}
|
|
18
28
|
}
|
|
19
29
|
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/nexus-aissam/bun-image-turbo/issues"
|
|
32
|
+
},
|
|
33
|
+
"description": "High-performance image processing for Bun and Node.js - resize, convert, compress with HEIC, WebP, AVIF, PNG, JPEG support",
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18.0.0"
|
|
36
|
+
},
|
|
20
37
|
"files": [
|
|
21
38
|
"dist"
|
|
22
39
|
],
|
|
23
|
-
"
|
|
24
|
-
"name": "image-turbo",
|
|
25
|
-
"binaryName": "image-turbo",
|
|
26
|
-
"packageName": "bun-image-turbo",
|
|
27
|
-
"targets": [
|
|
28
|
-
"x86_64-apple-darwin",
|
|
29
|
-
"aarch64-apple-darwin",
|
|
30
|
-
"x86_64-pc-windows-msvc",
|
|
31
|
-
"aarch64-pc-windows-msvc",
|
|
32
|
-
"x86_64-unknown-linux-gnu",
|
|
33
|
-
"aarch64-unknown-linux-gnu",
|
|
34
|
-
"x86_64-unknown-linux-musl"
|
|
35
|
-
]
|
|
36
|
-
},
|
|
37
|
-
"scripts": {
|
|
38
|
-
"build": "napi build --platform --release",
|
|
39
|
-
"build:debug": "napi build --platform",
|
|
40
|
-
"build:ts": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
41
|
-
"build:all": "bun run build && bun run build:ts",
|
|
42
|
-
"artifacts": "napi artifacts",
|
|
43
|
-
"version": "napi version",
|
|
44
|
-
"test": "bun test",
|
|
45
|
-
"bench": "bun run benchmarks/bench.ts",
|
|
46
|
-
"lint": "eslint src",
|
|
47
|
-
"clean": "rm -rf dist *.node npm"
|
|
48
|
-
},
|
|
40
|
+
"homepage": "https://nexus-aissam.github.io/bun-image-turbo/",
|
|
49
41
|
"keywords": [
|
|
50
42
|
"image",
|
|
51
43
|
"resize",
|
|
@@ -71,33 +63,41 @@
|
|
|
71
63
|
"fast",
|
|
72
64
|
"turbo"
|
|
73
65
|
],
|
|
74
|
-
"author": "Aissam Irhir <aissamirhir@gmail.com>",
|
|
75
66
|
"license": "MIT",
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
67
|
+
"napi": {
|
|
68
|
+
"name": "image-turbo",
|
|
69
|
+
"binaryName": "image-turbo",
|
|
70
|
+
"packageName": "bun-image-turbo",
|
|
71
|
+
"targets": [
|
|
72
|
+
"x86_64-apple-darwin",
|
|
73
|
+
"aarch64-apple-darwin",
|
|
74
|
+
"x86_64-pc-windows-msvc",
|
|
75
|
+
"aarch64-pc-windows-msvc",
|
|
76
|
+
"x86_64-unknown-linux-gnu",
|
|
77
|
+
"aarch64-unknown-linux-gnu",
|
|
78
|
+
"x86_64-unknown-linux-musl"
|
|
79
|
+
]
|
|
86
80
|
},
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
81
|
+
"scripts": {
|
|
82
|
+
"build": "napi build --platform --release",
|
|
83
|
+
"build:debug": "napi build --platform",
|
|
84
|
+
"build:ts": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
85
|
+
"build:all": "bun run build && bun run build:ts",
|
|
86
|
+
"artifacts": "napi artifacts",
|
|
87
|
+
"version": "napi version",
|
|
88
|
+
"test": "bun test",
|
|
89
|
+
"bench": "bun run benchmarks/bench.ts",
|
|
90
|
+
"lint": "eslint src",
|
|
91
|
+
"clean": "rm -rf dist *.node npm"
|
|
93
92
|
},
|
|
93
|
+
"types": "./dist/index.d.ts",
|
|
94
94
|
"optionalDependencies": {
|
|
95
|
-
"bun-image-turbo-darwin-arm64": "1.2.
|
|
96
|
-
"bun-image-turbo-darwin-x64": "1.2.
|
|
97
|
-
"bun-image-turbo-linux-arm64-gnu": "1.2.
|
|
98
|
-
"bun-image-turbo-linux-x64-gnu": "1.2.
|
|
99
|
-
"bun-image-turbo-linux-x64-musl": "1.2.
|
|
100
|
-
"bun-image-turbo-win32-arm64-msvc": "1.2.
|
|
101
|
-
"bun-image-turbo-win32-x64-msvc": "1.2.
|
|
95
|
+
"bun-image-turbo-darwin-arm64": "1.2.2",
|
|
96
|
+
"bun-image-turbo-darwin-x64": "1.2.2",
|
|
97
|
+
"bun-image-turbo-linux-arm64-gnu": "1.2.2",
|
|
98
|
+
"bun-image-turbo-linux-x64-gnu": "1.2.2",
|
|
99
|
+
"bun-image-turbo-linux-x64-musl": "1.2.2",
|
|
100
|
+
"bun-image-turbo-win32-arm64-msvc": "1.2.2",
|
|
101
|
+
"bun-image-turbo-win32-x64-msvc": "1.2.2"
|
|
102
102
|
}
|
|
103
103
|
}
|