cross-image 0.1.4 → 0.1.5

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 CHANGED
@@ -1,121 +1,143 @@
1
- # @cross/image
2
-
3
- A pure JavaScript, dependency-free, cross-runtime image processing library for
4
- Deno, Node.js, and Bun.
5
-
6
- 📚 **[Full Documentation](https://cross-org.github.io/image/)**
7
-
8
- ## Features
9
-
10
- - 🚀 **Pure JavaScript** - No native dependencies
11
- - 🔌 **Pluggable formats** - Easy to extend with custom formats
12
- - 📦 **Cross-runtime** - Works on Deno, Node.js (18+), and Bun
13
- - 🎨 **Multiple formats** - PNG, JPEG, WebP, GIF, TIFF, BMP, and RAW support
14
- - ✂️ **Image manipulation** - Resize with multiple algorithms
15
- - 🔧 **Simple API** - Easy to use, intuitive interface
16
-
17
- ## Installation
18
-
19
- ### Deno
20
-
21
- ```ts
22
- import { Image } from "jsr:@cross/image";
23
- ```
24
-
25
- ### Node.js
26
-
27
- ```bash
28
- npx jsr add @cross/image
29
- ```
30
-
31
- ```ts
32
- import { Image } from "@cross/image";
33
- ```
34
-
35
- ### Bun
36
-
37
- ```bash
38
- bunx jsr add @cross/image
39
- ```
40
-
41
- ```ts
42
- import { Image } from "@cross/image";
43
- ```
44
-
45
- ## Quick Start
46
-
47
- ```ts
48
- import { Image } from "@cross/image";
49
-
50
- // Read an image (auto-detects format)
51
- const data = await Deno.readFile("input.png");
52
- const image = await Image.read(data);
53
-
54
- console.log(`Image size: ${image.width}x${image.height}`);
55
-
56
- // Resize the image
57
- image.resize({ width: 800, height: 600 });
58
-
59
- // Save in a different format
60
- const jpeg = await image.save("jpeg");
61
- await Deno.writeFile("output.jpg", jpeg);
62
- ```
63
-
64
- ## Supported Formats
65
-
66
- | Format | Pure-JS | Notes |
67
- | ------ | ----------- | ------------------------------- |
68
- | PNG | ✅ Full | Complete pure-JS implementation |
69
- | BMP | Full | Complete pure-JS implementation |
70
- | GIF | Full | Complete pure-JS implementation |
71
- | RAW | ✅ Full | Uncompressed RGBA |
72
- | ASCII | Full | Text-based ASCII art |
73
- | JPEG | ⚠️ Baseline | Pure-JS baseline DCT only |
74
- | WebP | ⚠️ Lossless | Pure-JS lossless VP8L |
75
- | TIFF | ⚠️ Basic | Pure-JS uncompressed + LZW |
76
-
77
- See the
78
- [full format support documentation](https://cross-org.github.io/image/formats.html)
79
- for detailed compatibility information.
80
-
81
- ## Documentation
82
-
83
- - **[API Reference](https://cross-org.github.io/image/api.html)** - Complete API
84
- documentation
85
- - **[Examples](https://cross-org.github.io/image/examples.html)** - Usage
86
- examples for common tasks
87
- - **[Format Support](https://cross-org.github.io/image/formats.html)** -
88
- Supported formats and specifications
89
- - **[JPEG Implementation](https://cross-org.github.io/image/jpeg-implementation.html)** -
90
- Technical details for JPEG
91
- - **[WebP Implementation](https://cross-org.github.io/image/webp-implementation.html)** -
92
- Technical details for WebP
93
-
94
- ## Development
95
-
96
- ### Running Tests
97
-
98
- ```bash
99
- deno test -A
100
- ```
101
-
102
- ### Linting and Formatting
103
-
104
- ```bash
105
- deno fmt --check
106
- deno lint
107
- ```
108
-
109
- ### Type Checking
110
-
111
- ```bash
112
- deno check mod.ts
113
- ```
114
-
115
- ## License
116
-
117
- MIT License - see LICENSE file for details.
118
-
119
- ## Contributing
120
-
121
- Contributions are welcome! Please feel free to submit a Pull Request.
1
+ # @cross/image
2
+
3
+ A pure JavaScript, dependency-free, cross-runtime image processing library for
4
+ Deno, Node.js, and Bun.
5
+
6
+ 📚 **[Full Documentation](https://cross-org.github.io/image/)**
7
+
8
+ ## Features
9
+
10
+ - 🚀 **Pure JavaScript** - No native dependencies
11
+ - 🔌 **Pluggable formats** - Easy to extend with custom formats
12
+ - 📦 **Cross-runtime** - Works on Deno, Node.js (18+), and Bun
13
+ - 🎨 **Multiple formats** - PNG, JPEG, WebP, GIF, TIFF, BMP, and RAW support
14
+ - ✂️ **Image manipulation** - Resize with multiple algorithms
15
+ - 🔧 **Simple API** - Easy to use, intuitive interface
16
+
17
+ ## Installation
18
+
19
+ ### Deno
20
+
21
+ ```ts
22
+ import { Image } from "jsr:@cross/image";
23
+ ```
24
+
25
+ ### Node.js
26
+
27
+ ```bash
28
+ npx jsr add @cross/image
29
+ ```
30
+
31
+ ```ts
32
+ import { Image } from "@cross/image";
33
+ ```
34
+
35
+ ### Bun
36
+
37
+ ```bash
38
+ bunx jsr add @cross/image
39
+ ```
40
+
41
+ ```ts
42
+ import { Image } from "@cross/image";
43
+ ```
44
+
45
+ ## Quick Start
46
+
47
+ ### Deno
48
+
49
+ ```ts
50
+ import { Image } from "@cross/image";
51
+
52
+ // Decode an image (auto-detects format)
53
+ const data = await Deno.readFile("input.png");
54
+ const image = await Image.decode(data);
55
+
56
+ console.log(`Image size: ${image.width}x${image.height}`);
57
+
58
+ // Resize the image
59
+ image.resize({ width: 800, height: 600 });
60
+
61
+ // Encode in a different format
62
+ const jpeg = await image.encode("jpeg");
63
+ await Deno.writeFile("output.jpg", jpeg);
64
+ ```
65
+
66
+ ### Node.js
67
+
68
+ ```ts
69
+ import { Image } from "cross-image";
70
+ import { readFile, writeFile } from "node:fs/promises";
71
+
72
+ // Read an image (auto-detects format)
73
+ const data = await readFile("input.png");
74
+ const image = await Image.read(data);
75
+
76
+ console.log(`Image size: ${image.width}x${image.height}`);
77
+
78
+ // Resize the image
79
+ image.resize({ width: 800, height: 600 });
80
+
81
+ // Save in a different format
82
+ const jpeg = await image.save("jpeg");
83
+ await writeFile("output.jpg", jpeg);
84
+ ```
85
+
86
+ ## Supported Formats
87
+
88
+ | Format | Pure-JS | Notes |
89
+ | ------ | ----------- | ------------------------------- |
90
+ | PNG | Full | Complete pure-JS implementation |
91
+ | BMP | ✅ Full | Complete pure-JS implementation |
92
+ | GIF | Full | Complete pure-JS implementation |
93
+ | RAW | ✅ Full | Uncompressed RGBA |
94
+ | ASCII | ✅ Full | Text-based ASCII art |
95
+ | JPEG | ⚠️ Baseline | Pure-JS baseline DCT only |
96
+ | WebP | ⚠️ Lossless | Pure-JS lossless VP8L |
97
+ | TIFF | ⚠️ Basic | Pure-JS uncompressed + LZW |
98
+
99
+ See the
100
+ [full format support documentation](https://cross-org.github.io/image/formats.html)
101
+ for detailed compatibility information.
102
+
103
+ ## Documentation
104
+
105
+ - **[API Reference](https://cross-org.github.io/image/api.html)** - Complete API
106
+ documentation
107
+ - **[Examples](https://cross-org.github.io/image/examples.html)** - Usage
108
+ examples for common tasks
109
+ - **[Format Support](https://cross-org.github.io/image/formats.html)** -
110
+ Supported formats and specifications
111
+ - **[JPEG Implementation](https://cross-org.github.io/image/jpeg-implementation.html)** -
112
+ Technical details for JPEG
113
+ - **[WebP Implementation](https://cross-org.github.io/image/webp-implementation.html)** -
114
+ Technical details for WebP
115
+
116
+ ## Development
117
+
118
+ ### Running Tests
119
+
120
+ ```bash
121
+ deno test -A
122
+ ```
123
+
124
+ ### Linting and Formatting
125
+
126
+ ```bash
127
+ deno fmt --check
128
+ deno lint
129
+ ```
130
+
131
+ ### Type Checking
132
+
133
+ ```bash
134
+ deno check mod.ts
135
+ ```
136
+
137
+ ## License
138
+
139
+ MIT License - see LICENSE file for details.
140
+
141
+ ## Contributing
142
+
143
+ Contributions are welcome! Please feel free to submit a Pull Request.
package/esm/mod.d.ts CHANGED
@@ -2,21 +2,21 @@
2
2
  * @module @cross/image
3
3
  *
4
4
  * A pure JavaScript, dependency-free, cross-runtime image processing library.
5
- * Supports reading, resizing, and saving common image formats (PNG, JPEG, WebP, GIF, TIFF, BMP, RAW).
5
+ * Supports decoding, resizing, and encoding common image formats (PNG, JPEG, WebP, GIF, TIFF, BMP, RAW).
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
9
  * import { Image } from "@cross/image";
10
10
  *
11
- * // Read an image
11
+ * // Decode an image
12
12
  * const data = await Deno.readFile("input.png");
13
- * const image = await Image.read(data);
13
+ * const image = await Image.decode(data);
14
14
  *
15
15
  * // Resize it
16
16
  * image.resize({ width: 200, height: 200 });
17
17
  *
18
- * // Save as different format
19
- * const output = await image.save("jpeg");
18
+ * // Encode as different format
19
+ * const output = await image.encode("jpeg");
20
20
  * await Deno.writeFile("output.jpg", output);
21
21
  * ```
22
22
  */
package/esm/mod.js CHANGED
@@ -2,21 +2,21 @@
2
2
  * @module @cross/image
3
3
  *
4
4
  * A pure JavaScript, dependency-free, cross-runtime image processing library.
5
- * Supports reading, resizing, and saving common image formats (PNG, JPEG, WebP, GIF, TIFF, BMP, RAW).
5
+ * Supports decoding, resizing, and encoding common image formats (PNG, JPEG, WebP, GIF, TIFF, BMP, RAW).
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
9
  * import { Image } from "@cross/image";
10
10
  *
11
- * // Read an image
11
+ * // Decode an image
12
12
  * const data = await Deno.readFile("input.png");
13
- * const image = await Image.read(data);
13
+ * const image = await Image.decode(data);
14
14
  *
15
15
  * // Resize it
16
16
  * image.resize({ width: 200, height: 200 });
17
17
  *
18
- * // Save as different format
19
- * const output = await image.save("jpeg");
18
+ * // Encode as different format
19
+ * const output = await image.encode("jpeg");
20
20
  * await Deno.writeFile("output.jpg", output);
21
21
  * ```
22
22
  */
@@ -72,24 +72,49 @@ export declare class Image {
72
72
  * Get all registered formats
73
73
  */
74
74
  static getFormats(): readonly ImageFormat[];
75
+ /**
76
+ * Decode an image from bytes
77
+ * @param data Raw image data
78
+ * @param format Optional format hint (e.g., "png", "jpeg", "webp")
79
+ * @returns Image instance
80
+ */
81
+ static decode(data: Uint8Array, format?: string): Promise<Image>;
75
82
  /**
76
83
  * Read an image from bytes
84
+ * @deprecated Use `decode()` instead. This method will be removed in a future version.
77
85
  * @param data Raw image data
78
86
  * @param format Optional format hint (e.g., "png", "jpeg", "webp")
79
87
  * @returns Image instance
80
88
  */
81
89
  static read(data: Uint8Array, format?: string): Promise<Image>;
90
+ /**
91
+ * Decode all frames from a multi-frame image (GIF animation, multi-page TIFF)
92
+ * @param data Raw image data
93
+ * @param format Optional format hint (e.g., "gif", "tiff")
94
+ * @returns MultiFrameImageData with all frames
95
+ */
96
+ static decodeFrames(data: Uint8Array, format?: string): Promise<MultiFrameImageData>;
82
97
  /**
83
98
  * Read all frames from a multi-frame image (GIF animation, multi-page TIFF)
99
+ * @deprecated Use `decodeFrames()` instead. This method will be removed in a future version.
84
100
  * @param data Raw image data
85
101
  * @param format Optional format hint (e.g., "gif", "tiff")
86
102
  * @returns MultiFrameImageData with all frames
87
103
  */
88
104
  static readFrames(data: Uint8Array, format?: string): Promise<MultiFrameImageData>;
105
+ /**
106
+ * Encode multi-frame image data to bytes in the specified format
107
+ * @param format Format name (e.g., "gif", "tiff")
108
+ * @param imageData Multi-frame image data to encode
109
+ * @param options Optional format-specific encoding options
110
+ * @returns Encoded image bytes
111
+ */
112
+ static encodeFrames(format: string, imageData: MultiFrameImageData, options?: unknown): Promise<Uint8Array>;
89
113
  /**
90
114
  * Save multi-frame image data to bytes in the specified format
115
+ * @deprecated Use `encodeFrames()` instead. This method will be removed in a future version.
91
116
  * @param format Format name (e.g., "gif", "tiff")
92
- * @param imageData Multi-frame image data to save
117
+ * @param imageData Multi-frame image data to encode
93
118
  * @param options Optional format-specific encoding options
94
119
  * @returns Encoded image bytes
95
120
  */
@@ -108,8 +133,16 @@ export declare class Image {
108
133
  * @returns This image instance for chaining
109
134
  */
110
135
  resize(options: ResizeOptions): this;
136
+ /**
137
+ * Encode the image to bytes in the specified format
138
+ * @param format Format name (e.g., "png", "jpeg", "webp", "ascii")
139
+ * @param options Optional format-specific encoding options
140
+ * @returns Encoded image bytes
141
+ */
142
+ encode(format: string, options?: unknown): Promise<Uint8Array>;
111
143
  /**
112
144
  * Save the image to bytes in the specified format
145
+ * @deprecated Use `encode()` instead. This method will be removed in a future version.
113
146
  * @param format Format name (e.g., "png", "jpeg", "webp", "ascii")
114
147
  * @param options Optional format-specific encoding options
115
148
  * @returns Encoded image bytes
package/esm/src/image.js CHANGED
@@ -151,12 +151,12 @@ export class Image {
151
151
  return Image.formats;
152
152
  }
153
153
  /**
154
- * Read an image from bytes
154
+ * Decode an image from bytes
155
155
  * @param data Raw image data
156
156
  * @param format Optional format hint (e.g., "png", "jpeg", "webp")
157
157
  * @returns Image instance
158
158
  */
159
- static async read(data, format) {
159
+ static async decode(data, format) {
160
160
  const image = new Image();
161
161
  // Try specified format first
162
162
  if (format) {
@@ -176,12 +176,22 @@ export class Image {
176
176
  throw new Error("Unsupported or unrecognized image format");
177
177
  }
178
178
  /**
179
- * Read all frames from a multi-frame image (GIF animation, multi-page TIFF)
179
+ * Read an image from bytes
180
+ * @deprecated Use `decode()` instead. This method will be removed in a future version.
181
+ * @param data Raw image data
182
+ * @param format Optional format hint (e.g., "png", "jpeg", "webp")
183
+ * @returns Image instance
184
+ */
185
+ static read(data, format) {
186
+ return Image.decode(data, format);
187
+ }
188
+ /**
189
+ * Decode all frames from a multi-frame image (GIF animation, multi-page TIFF)
180
190
  * @param data Raw image data
181
191
  * @param format Optional format hint (e.g., "gif", "tiff")
182
192
  * @returns MultiFrameImageData with all frames
183
193
  */
184
- static async readFrames(data, format) {
194
+ static async decodeFrames(data, format) {
185
195
  // Try specified format first
186
196
  if (format) {
187
197
  const handler = Image.formats.find((f) => f.name === format);
@@ -198,13 +208,23 @@ export class Image {
198
208
  throw new Error("Unsupported or unrecognized multi-frame image format");
199
209
  }
200
210
  /**
201
- * Save multi-frame image data to bytes in the specified format
211
+ * Read all frames from a multi-frame image (GIF animation, multi-page TIFF)
212
+ * @deprecated Use `decodeFrames()` instead. This method will be removed in a future version.
213
+ * @param data Raw image data
214
+ * @param format Optional format hint (e.g., "gif", "tiff")
215
+ * @returns MultiFrameImageData with all frames
216
+ */
217
+ static readFrames(data, format) {
218
+ return Image.decodeFrames(data, format);
219
+ }
220
+ /**
221
+ * Encode multi-frame image data to bytes in the specified format
202
222
  * @param format Format name (e.g., "gif", "tiff")
203
- * @param imageData Multi-frame image data to save
223
+ * @param imageData Multi-frame image data to encode
204
224
  * @param options Optional format-specific encoding options
205
225
  * @returns Encoded image bytes
206
226
  */
207
- static async saveFrames(format, imageData, options) {
227
+ static async encodeFrames(format, imageData, options) {
208
228
  const handler = Image.formats.find((f) => f.name === format);
209
229
  if (!handler) {
210
230
  throw new Error(`Unsupported format: ${format}`);
@@ -214,6 +234,17 @@ export class Image {
214
234
  }
215
235
  return await handler.encodeFrames(imageData, options);
216
236
  }
237
+ /**
238
+ * Save multi-frame image data to bytes in the specified format
239
+ * @deprecated Use `encodeFrames()` instead. This method will be removed in a future version.
240
+ * @param format Format name (e.g., "gif", "tiff")
241
+ * @param imageData Multi-frame image data to encode
242
+ * @param options Optional format-specific encoding options
243
+ * @returns Encoded image bytes
244
+ */
245
+ static saveFrames(format, imageData, options) {
246
+ return Image.encodeFrames(format, imageData, options);
247
+ }
217
248
  /**
218
249
  * Create an image from raw RGBA data
219
250
  * @param width Image width
@@ -270,12 +301,12 @@ export class Image {
270
301
  return this;
271
302
  }
272
303
  /**
273
- * Save the image to bytes in the specified format
304
+ * Encode the image to bytes in the specified format
274
305
  * @param format Format name (e.g., "png", "jpeg", "webp", "ascii")
275
306
  * @param options Optional format-specific encoding options
276
307
  * @returns Encoded image bytes
277
308
  */
278
- async save(format, options) {
309
+ async encode(format, options) {
279
310
  if (!this.imageData)
280
311
  throw new Error("No image loaded");
281
312
  const handler = Image.formats.find((f) => f.name === format);
@@ -284,6 +315,16 @@ export class Image {
284
315
  }
285
316
  return await handler.encode(this.imageData, options);
286
317
  }
318
+ /**
319
+ * Save the image to bytes in the specified format
320
+ * @deprecated Use `encode()` instead. This method will be removed in a future version.
321
+ * @param format Format name (e.g., "png", "jpeg", "webp", "ascii")
322
+ * @param options Optional format-specific encoding options
323
+ * @returns Encoded image bytes
324
+ */
325
+ save(format, options) {
326
+ return this.encode(format, options);
327
+ }
287
328
  /**
288
329
  * Clone this image
289
330
  * @returns New image instance with copied data and metadata
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cross-image",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "A pure JavaScript, dependency-free, cross-runtime image processing library for Deno, Node.js, and Bun.",
5
5
  "keywords": [
6
6
  "image",
package/script/mod.d.ts CHANGED
@@ -2,21 +2,21 @@
2
2
  * @module @cross/image
3
3
  *
4
4
  * A pure JavaScript, dependency-free, cross-runtime image processing library.
5
- * Supports reading, resizing, and saving common image formats (PNG, JPEG, WebP, GIF, TIFF, BMP, RAW).
5
+ * Supports decoding, resizing, and encoding common image formats (PNG, JPEG, WebP, GIF, TIFF, BMP, RAW).
6
6
  *
7
7
  * @example
8
8
  * ```ts
9
9
  * import { Image } from "@cross/image";
10
10
  *
11
- * // Read an image
11
+ * // Decode an image
12
12
  * const data = await Deno.readFile("input.png");
13
- * const image = await Image.read(data);
13
+ * const image = await Image.decode(data);
14
14
  *
15
15
  * // Resize it
16
16
  * image.resize({ width: 200, height: 200 });
17
17
  *
18
- * // Save as different format
19
- * const output = await image.save("jpeg");
18
+ * // Encode as different format
19
+ * const output = await image.encode("jpeg");
20
20
  * await Deno.writeFile("output.jpg", output);
21
21
  * ```
22
22
  */
package/script/mod.js CHANGED
@@ -3,21 +3,21 @@
3
3
  * @module @cross/image
4
4
  *
5
5
  * A pure JavaScript, dependency-free, cross-runtime image processing library.
6
- * Supports reading, resizing, and saving common image formats (PNG, JPEG, WebP, GIF, TIFF, BMP, RAW).
6
+ * Supports decoding, resizing, and encoding common image formats (PNG, JPEG, WebP, GIF, TIFF, BMP, RAW).
7
7
  *
8
8
  * @example
9
9
  * ```ts
10
10
  * import { Image } from "@cross/image";
11
11
  *
12
- * // Read an image
12
+ * // Decode an image
13
13
  * const data = await Deno.readFile("input.png");
14
- * const image = await Image.read(data);
14
+ * const image = await Image.decode(data);
15
15
  *
16
16
  * // Resize it
17
17
  * image.resize({ width: 200, height: 200 });
18
18
  *
19
- * // Save as different format
20
- * const output = await image.save("jpeg");
19
+ * // Encode as different format
20
+ * const output = await image.encode("jpeg");
21
21
  * await Deno.writeFile("output.jpg", output);
22
22
  * ```
23
23
  */
@@ -72,24 +72,49 @@ export declare class Image {
72
72
  * Get all registered formats
73
73
  */
74
74
  static getFormats(): readonly ImageFormat[];
75
+ /**
76
+ * Decode an image from bytes
77
+ * @param data Raw image data
78
+ * @param format Optional format hint (e.g., "png", "jpeg", "webp")
79
+ * @returns Image instance
80
+ */
81
+ static decode(data: Uint8Array, format?: string): Promise<Image>;
75
82
  /**
76
83
  * Read an image from bytes
84
+ * @deprecated Use `decode()` instead. This method will be removed in a future version.
77
85
  * @param data Raw image data
78
86
  * @param format Optional format hint (e.g., "png", "jpeg", "webp")
79
87
  * @returns Image instance
80
88
  */
81
89
  static read(data: Uint8Array, format?: string): Promise<Image>;
90
+ /**
91
+ * Decode all frames from a multi-frame image (GIF animation, multi-page TIFF)
92
+ * @param data Raw image data
93
+ * @param format Optional format hint (e.g., "gif", "tiff")
94
+ * @returns MultiFrameImageData with all frames
95
+ */
96
+ static decodeFrames(data: Uint8Array, format?: string): Promise<MultiFrameImageData>;
82
97
  /**
83
98
  * Read all frames from a multi-frame image (GIF animation, multi-page TIFF)
99
+ * @deprecated Use `decodeFrames()` instead. This method will be removed in a future version.
84
100
  * @param data Raw image data
85
101
  * @param format Optional format hint (e.g., "gif", "tiff")
86
102
  * @returns MultiFrameImageData with all frames
87
103
  */
88
104
  static readFrames(data: Uint8Array, format?: string): Promise<MultiFrameImageData>;
105
+ /**
106
+ * Encode multi-frame image data to bytes in the specified format
107
+ * @param format Format name (e.g., "gif", "tiff")
108
+ * @param imageData Multi-frame image data to encode
109
+ * @param options Optional format-specific encoding options
110
+ * @returns Encoded image bytes
111
+ */
112
+ static encodeFrames(format: string, imageData: MultiFrameImageData, options?: unknown): Promise<Uint8Array>;
89
113
  /**
90
114
  * Save multi-frame image data to bytes in the specified format
115
+ * @deprecated Use `encodeFrames()` instead. This method will be removed in a future version.
91
116
  * @param format Format name (e.g., "gif", "tiff")
92
- * @param imageData Multi-frame image data to save
117
+ * @param imageData Multi-frame image data to encode
93
118
  * @param options Optional format-specific encoding options
94
119
  * @returns Encoded image bytes
95
120
  */
@@ -108,8 +133,16 @@ export declare class Image {
108
133
  * @returns This image instance for chaining
109
134
  */
110
135
  resize(options: ResizeOptions): this;
136
+ /**
137
+ * Encode the image to bytes in the specified format
138
+ * @param format Format name (e.g., "png", "jpeg", "webp", "ascii")
139
+ * @param options Optional format-specific encoding options
140
+ * @returns Encoded image bytes
141
+ */
142
+ encode(format: string, options?: unknown): Promise<Uint8Array>;
111
143
  /**
112
144
  * Save the image to bytes in the specified format
145
+ * @deprecated Use `encode()` instead. This method will be removed in a future version.
113
146
  * @param format Format name (e.g., "png", "jpeg", "webp", "ascii")
114
147
  * @param options Optional format-specific encoding options
115
148
  * @returns Encoded image bytes
@@ -154,12 +154,12 @@ class Image {
154
154
  return Image.formats;
155
155
  }
156
156
  /**
157
- * Read an image from bytes
157
+ * Decode an image from bytes
158
158
  * @param data Raw image data
159
159
  * @param format Optional format hint (e.g., "png", "jpeg", "webp")
160
160
  * @returns Image instance
161
161
  */
162
- static async read(data, format) {
162
+ static async decode(data, format) {
163
163
  const image = new Image();
164
164
  // Try specified format first
165
165
  if (format) {
@@ -179,12 +179,22 @@ class Image {
179
179
  throw new Error("Unsupported or unrecognized image format");
180
180
  }
181
181
  /**
182
- * Read all frames from a multi-frame image (GIF animation, multi-page TIFF)
182
+ * Read an image from bytes
183
+ * @deprecated Use `decode()` instead. This method will be removed in a future version.
184
+ * @param data Raw image data
185
+ * @param format Optional format hint (e.g., "png", "jpeg", "webp")
186
+ * @returns Image instance
187
+ */
188
+ static read(data, format) {
189
+ return Image.decode(data, format);
190
+ }
191
+ /**
192
+ * Decode all frames from a multi-frame image (GIF animation, multi-page TIFF)
183
193
  * @param data Raw image data
184
194
  * @param format Optional format hint (e.g., "gif", "tiff")
185
195
  * @returns MultiFrameImageData with all frames
186
196
  */
187
- static async readFrames(data, format) {
197
+ static async decodeFrames(data, format) {
188
198
  // Try specified format first
189
199
  if (format) {
190
200
  const handler = Image.formats.find((f) => f.name === format);
@@ -201,13 +211,23 @@ class Image {
201
211
  throw new Error("Unsupported or unrecognized multi-frame image format");
202
212
  }
203
213
  /**
204
- * Save multi-frame image data to bytes in the specified format
214
+ * Read all frames from a multi-frame image (GIF animation, multi-page TIFF)
215
+ * @deprecated Use `decodeFrames()` instead. This method will be removed in a future version.
216
+ * @param data Raw image data
217
+ * @param format Optional format hint (e.g., "gif", "tiff")
218
+ * @returns MultiFrameImageData with all frames
219
+ */
220
+ static readFrames(data, format) {
221
+ return Image.decodeFrames(data, format);
222
+ }
223
+ /**
224
+ * Encode multi-frame image data to bytes in the specified format
205
225
  * @param format Format name (e.g., "gif", "tiff")
206
- * @param imageData Multi-frame image data to save
226
+ * @param imageData Multi-frame image data to encode
207
227
  * @param options Optional format-specific encoding options
208
228
  * @returns Encoded image bytes
209
229
  */
210
- static async saveFrames(format, imageData, options) {
230
+ static async encodeFrames(format, imageData, options) {
211
231
  const handler = Image.formats.find((f) => f.name === format);
212
232
  if (!handler) {
213
233
  throw new Error(`Unsupported format: ${format}`);
@@ -217,6 +237,17 @@ class Image {
217
237
  }
218
238
  return await handler.encodeFrames(imageData, options);
219
239
  }
240
+ /**
241
+ * Save multi-frame image data to bytes in the specified format
242
+ * @deprecated Use `encodeFrames()` instead. This method will be removed in a future version.
243
+ * @param format Format name (e.g., "gif", "tiff")
244
+ * @param imageData Multi-frame image data to encode
245
+ * @param options Optional format-specific encoding options
246
+ * @returns Encoded image bytes
247
+ */
248
+ static saveFrames(format, imageData, options) {
249
+ return Image.encodeFrames(format, imageData, options);
250
+ }
220
251
  /**
221
252
  * Create an image from raw RGBA data
222
253
  * @param width Image width
@@ -273,12 +304,12 @@ class Image {
273
304
  return this;
274
305
  }
275
306
  /**
276
- * Save the image to bytes in the specified format
307
+ * Encode the image to bytes in the specified format
277
308
  * @param format Format name (e.g., "png", "jpeg", "webp", "ascii")
278
309
  * @param options Optional format-specific encoding options
279
310
  * @returns Encoded image bytes
280
311
  */
281
- async save(format, options) {
312
+ async encode(format, options) {
282
313
  if (!this.imageData)
283
314
  throw new Error("No image loaded");
284
315
  const handler = Image.formats.find((f) => f.name === format);
@@ -287,6 +318,16 @@ class Image {
287
318
  }
288
319
  return await handler.encode(this.imageData, options);
289
320
  }
321
+ /**
322
+ * Save the image to bytes in the specified format
323
+ * @deprecated Use `encode()` instead. This method will be removed in a future version.
324
+ * @param format Format name (e.g., "png", "jpeg", "webp", "ascii")
325
+ * @param options Optional format-specific encoding options
326
+ * @returns Encoded image bytes
327
+ */
328
+ save(format, options) {
329
+ return this.encode(format, options);
330
+ }
290
331
  /**
291
332
  * Clone this image
292
333
  * @returns New image instance with copied data and metadata