cross-image 0.2.4 → 0.4.0

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.
Files changed (105) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +507 -333
  3. package/esm/mod.d.ts +4 -4
  4. package/esm/mod.js +2 -2
  5. package/esm/src/formats/apng.d.ts +5 -5
  6. package/esm/src/formats/apng.js +7 -9
  7. package/esm/src/formats/ascii.d.ts +3 -3
  8. package/esm/src/formats/ascii.js +1 -1
  9. package/esm/src/formats/avif.d.ts +3 -3
  10. package/esm/src/formats/avif.js +7 -7
  11. package/esm/src/formats/bmp.d.ts +3 -3
  12. package/esm/src/formats/bmp.js +2 -2
  13. package/esm/src/formats/dng.d.ts +1 -1
  14. package/esm/src/formats/dng.js +1 -1
  15. package/esm/src/formats/gif.d.ts +4 -4
  16. package/esm/src/formats/gif.js +14 -10
  17. package/esm/src/formats/heic.d.ts +3 -3
  18. package/esm/src/formats/heic.js +7 -7
  19. package/esm/src/formats/ico.d.ts +3 -3
  20. package/esm/src/formats/ico.js +4 -4
  21. package/esm/src/formats/jpeg.d.ts +3 -3
  22. package/esm/src/formats/jpeg.js +23 -11
  23. package/esm/src/formats/pam.d.ts +3 -3
  24. package/esm/src/formats/pam.js +2 -2
  25. package/esm/src/formats/pcx.d.ts +3 -3
  26. package/esm/src/formats/pcx.js +2 -2
  27. package/esm/src/formats/png.d.ts +3 -3
  28. package/esm/src/formats/png.js +2 -2
  29. package/esm/src/formats/png_base.js +2 -5
  30. package/esm/src/formats/ppm.d.ts +3 -3
  31. package/esm/src/formats/ppm.js +2 -2
  32. package/esm/src/formats/tiff.d.ts +7 -18
  33. package/esm/src/formats/tiff.js +86 -21
  34. package/esm/src/formats/webp.d.ts +3 -3
  35. package/esm/src/formats/webp.js +11 -8
  36. package/esm/src/image.d.ts +11 -3
  37. package/esm/src/image.js +37 -21
  38. package/esm/src/types.d.ts +56 -4
  39. package/esm/src/utils/gif_decoder.d.ts +4 -1
  40. package/esm/src/utils/gif_decoder.js +91 -65
  41. package/esm/src/utils/image_processing.js +144 -70
  42. package/esm/src/utils/jpeg_decoder.d.ts +17 -4
  43. package/esm/src/utils/jpeg_decoder.js +448 -83
  44. package/esm/src/utils/jpeg_encoder.d.ts +15 -1
  45. package/esm/src/utils/jpeg_encoder.js +263 -24
  46. package/esm/src/utils/resize.js +51 -20
  47. package/esm/src/utils/tiff_deflate.d.ts +18 -0
  48. package/esm/src/utils/tiff_deflate.js +27 -0
  49. package/esm/src/utils/tiff_packbits.d.ts +24 -0
  50. package/esm/src/utils/tiff_packbits.js +90 -0
  51. package/esm/src/utils/webp_decoder.d.ts +3 -1
  52. package/esm/src/utils/webp_decoder.js +144 -63
  53. package/esm/src/utils/webp_encoder.js +5 -11
  54. package/package.json +1 -1
  55. package/script/mod.d.ts +4 -4
  56. package/script/mod.js +2 -2
  57. package/script/src/formats/apng.d.ts +5 -5
  58. package/script/src/formats/apng.js +7 -9
  59. package/script/src/formats/ascii.d.ts +3 -3
  60. package/script/src/formats/ascii.js +1 -1
  61. package/script/src/formats/avif.d.ts +3 -3
  62. package/script/src/formats/avif.js +7 -7
  63. package/script/src/formats/bmp.d.ts +3 -3
  64. package/script/src/formats/bmp.js +2 -2
  65. package/script/src/formats/dng.d.ts +1 -1
  66. package/script/src/formats/dng.js +1 -1
  67. package/script/src/formats/gif.d.ts +4 -4
  68. package/script/src/formats/gif.js +14 -10
  69. package/script/src/formats/heic.d.ts +3 -3
  70. package/script/src/formats/heic.js +7 -7
  71. package/script/src/formats/ico.d.ts +3 -3
  72. package/script/src/formats/ico.js +4 -4
  73. package/script/src/formats/jpeg.d.ts +3 -3
  74. package/script/src/formats/jpeg.js +23 -11
  75. package/script/src/formats/pam.d.ts +3 -3
  76. package/script/src/formats/pam.js +2 -2
  77. package/script/src/formats/pcx.d.ts +3 -3
  78. package/script/src/formats/pcx.js +2 -2
  79. package/script/src/formats/png.d.ts +3 -3
  80. package/script/src/formats/png.js +2 -2
  81. package/script/src/formats/png_base.js +2 -5
  82. package/script/src/formats/ppm.d.ts +3 -3
  83. package/script/src/formats/ppm.js +2 -2
  84. package/script/src/formats/tiff.d.ts +7 -18
  85. package/script/src/formats/tiff.js +86 -21
  86. package/script/src/formats/webp.d.ts +3 -3
  87. package/script/src/formats/webp.js +11 -8
  88. package/script/src/image.d.ts +11 -3
  89. package/script/src/image.js +36 -20
  90. package/script/src/types.d.ts +56 -4
  91. package/script/src/utils/gif_decoder.d.ts +4 -1
  92. package/script/src/utils/gif_decoder.js +91 -65
  93. package/script/src/utils/image_processing.js +144 -70
  94. package/script/src/utils/jpeg_decoder.d.ts +17 -4
  95. package/script/src/utils/jpeg_decoder.js +448 -83
  96. package/script/src/utils/jpeg_encoder.d.ts +15 -1
  97. package/script/src/utils/jpeg_encoder.js +263 -24
  98. package/script/src/utils/resize.js +51 -20
  99. package/script/src/utils/tiff_deflate.d.ts +18 -0
  100. package/script/src/utils/tiff_deflate.js +31 -0
  101. package/script/src/utils/tiff_packbits.d.ts +24 -0
  102. package/script/src/utils/tiff_packbits.js +94 -0
  103. package/script/src/utils/webp_decoder.d.ts +3 -1
  104. package/script/src/utils/webp_decoder.js +144 -63
  105. package/script/src/utils/webp_encoder.js +5 -11
package/README.md CHANGED
@@ -1,333 +1,507 @@
1
- # @cross/image
2
-
3
- A pure JavaScript, dependency-free, cross-runtime image processing library for
4
- Deno, Node.js, and Bun. Decode, encode, manipulate, and process images in
5
- multiple formats including PNG, JPEG, WebP, GIF, and more—all without native
6
- dependencies.
7
-
8
- 📚 **[Full Documentation](https://cross-image.56k.guru/)**
9
-
10
- ## Features
11
-
12
- - 🚀 **Pure JavaScript** - No native dependencies
13
- - 🔌 **Pluggable formats** - Easy to extend with custom formats
14
- - 📦 **Cross-runtime** - Works on Deno, Node.js (18+), and Bun
15
- - 🎨 **Multiple formats** - PNG, APNG, JPEG, WebP, GIF, TIFF, BMP, ICO, DNG,
16
- PAM, PPM, PCX, ASCII, HEIC, and AVIF support
17
- - ✂️ **Image manipulation** - Resize, crop, composite, and more
18
- - 🎛️ **Image processing** - Chainable filters including `brightness`,
19
- `contrast`, `saturation`, `hue`, `exposure`, `blur`, `sharpen`, `sepia`, and
20
- more
21
- - 🖌️ **Drawing operations** - Create, fill, and manipulate pixels
22
- - 🧩 **Multi-frame** - Decode/encode animated GIFs, APNGs and multi-page TIFFs
23
- - 🔧 **Simple API** - Easy to use, intuitive interface
24
-
25
- ## Installation
26
-
27
- ### Deno
28
-
29
- ```ts
30
- import { Image } from "jsr:@cross/image";
31
- ```
32
-
33
- ### Node.js
34
-
35
- ```bash
36
- npm install cross-image
37
- ```
38
-
39
- ```ts
40
- import { Image } from "cross-image";
41
- ```
42
-
43
- ### Bun
44
-
45
- ```bash
46
- npm install cross-image
47
- ```
48
-
49
- ```ts
50
- import { Image } from "cross-image";
51
- ```
52
-
53
- ## Quick Start
54
-
55
- ### Deno
56
-
57
- ```ts
58
- import { Image } from "@cross/image";
59
-
60
- // Decode an image (auto-detects format)
61
- const data = await Deno.readFile("input.png");
62
- const image = await Image.decode(data);
63
-
64
- console.log(`Image size: ${image.width}x${image.height}`);
65
-
66
- // Create a new blank image
67
- const canvas = Image.create(800, 600, 255, 255, 255); // white background
68
-
69
- // Composite the loaded image on top
70
- canvas.composite(image, 50, 50);
71
-
72
- // Apply image processing filters
73
- canvas
74
- .brightness(0.1)
75
- .contrast(0.2)
76
- .saturation(-0.1)
77
- .blur(1)
78
- .sharpen(0.3);
79
-
80
- // Encode in a different format
81
- const jpeg = await canvas.encode("jpeg");
82
- await Deno.writeFile("output.jpg", jpeg);
83
- ```
84
-
85
- ### Node.js
86
-
87
- ```ts
88
- import { Image } from "cross-image";
89
- import { readFile, writeFile } from "node:fs/promises";
90
-
91
- // Read an image (auto-detects format)
92
- const data = await readFile("input.png");
93
- const image = await Image.decode(data);
94
-
95
- console.log(`Image size: ${image.width}x${image.height}`);
96
-
97
- // Resize the image
98
- image.resize({ width: 800, height: 600 });
99
-
100
- // Save in a different format
101
- const jpeg = await image.encode("jpeg");
102
- await writeFile("output.jpg", jpeg);
103
- ```
104
-
105
- ## Supported Formats
106
-
107
- | Format | Pure-JS | Notes |
108
- | ------ | ----------- | ------------------------------------------------- |
109
- | PNG | Full | Complete pure-JS implementation |
110
- | APNG | Full | Animated PNG with multi-frame |
111
- | BMP | ✅ Full | Complete pure-JS implementation |
112
- | ICO | ✅ Full | Windows Icon format |
113
- | GIF | ✅ Full | Animated GIF with multi-frame |
114
- | DNG | Full | Linear DNG (Uncompressed RGBA) |
115
- | PAM | Full | Netpbm PAM format |
116
- | PPM | Full | Netpbm PPM format (P3/P6) |
117
- | PCX | ✅ Full | ZSoft PCX (RLE compressed) |
118
- | ASCII | ✅ Full | Text-based ASCII art |
119
- | JPEG | ⚠️ Baseline | Pure-JS baseline DCT only |
120
- | WebP | ⚠️ Lossless | Pure-JS lossless VP8L |
121
- | TIFF | ⚠️ Basic | Pure-JS uncompressed, LZW, & grayscale |
122
- | HEIC | 🔌 Runtime | Requires ImageDecoder/OffscreenCanvas API support |
123
- | AVIF | 🔌 Runtime | Requires ImageDecoder/OffscreenCanvas API support |
124
-
125
- See the
126
- [full format support documentation](https://cross-image.56k.guru/formats/) for
127
- detailed compatibility information.
128
-
129
- ## Metadata Support
130
-
131
- @cross/image provides comprehensive EXIF 3.0 compliant metadata support for
132
- image files, including camera information, GPS coordinates, and InteropIFD
133
- compatibility markers.
134
-
135
- ### Supported Metadata Fields
136
-
137
- **Basic Metadata:**
138
-
139
- - `title`, `description`, `author`, `copyright`
140
- - `creationDate` - Date/time image was created
141
-
142
- **Camera Settings (JPEG, TIFF, WebP via XMP):**
143
-
144
- - `cameraMake`, `cameraModel` - Camera manufacturer and model
145
- - `lensMake`, `lensModel` - Lens information
146
- - `iso` - ISO speed rating
147
- - `exposureTime` - Shutter speed in seconds
148
- - `fNumber` - Aperture (f-number)
149
- - `focalLength` - Focal length in mm
150
- - `flash`, `whiteBalance` - Capture settings
151
- - `orientation` - Image orientation (1=normal, 3=180°, 6=90°CW, 8=90°CCW)
152
- - `software` - Software used
153
- - `userComment` - User notes
154
-
155
- **GPS Coordinates (All EXIF formats: JPEG, PNG, WebP, TIFF):**
156
-
157
- - `latitude`, `longitude` - GPS coordinates in decimal degrees
158
- - Full microsecond precision with DMS (degrees-minutes-seconds) conversion
159
-
160
- **DPI (JPEG, PNG, TIFF):**
161
-
162
- - `dpiX`, `dpiY` - Dots per inch for printing
163
-
164
- ### EXIF 3.0 Specification Compliance
165
-
166
- The library implements the EXIF 3.0 specification with:
167
-
168
- - **50+ Exif Sub-IFD tags** for comprehensive camera metadata
169
- - **30+ IFD0 tags** for image information
170
- - **InteropIFD support** for format compatibility (R98/sRGB, R03/Adobe RGB,
171
- THM/thumbnail)
172
- - **GPS IFD** with proper coordinate conversion
173
- - All EXIF data types (BYTE, ASCII, SHORT, LONG, RATIONAL, etc.)
174
-
175
- ### Example Usage
176
-
177
- ```typescript
178
- import { Image } from "@cross/image";
179
-
180
- // Load an image
181
- const data = await Deno.readFile("photo.jpg");
182
- const image = await Image.decode(data);
183
-
184
- // Set metadata
185
- image.setMetadata({
186
- author: "Jane Photographer",
187
- copyright: "© 2024",
188
- cameraMake: "Canon",
189
- cameraModel: "EOS R5",
190
- iso: 800,
191
- exposureTime: 0.004, // 1/250s
192
- fNumber: 2.8,
193
- focalLength: 50,
194
- });
195
-
196
- // Set GPS coordinates
197
- image.setPosition(40.7128, -74.0060); // NYC
198
-
199
- // Check what metadata a format supports
200
- const jpegSupports = Image.getSupportedMetadata("jpeg");
201
- console.log(jpegSupports); // Includes ISO, camera info, GPS, etc.
202
-
203
- // Save with metadata
204
- const jpeg = await image.save("jpeg");
205
- await Deno.writeFile("output.jpg", jpeg);
206
-
207
- // Metadata is preserved on reload!
208
- const loaded = await Image.decode(jpeg);
209
- console.log(loaded.metadata?.cameraMake); // "Canon"
210
- console.log(loaded.getPosition()); // { latitude: 40.7128, longitude: -74.0060 }
211
- ```
212
-
213
- ### Extracting Metadata Without Decoding
214
-
215
- For quickly reading metadata from images without the overhead of decoding pixel
216
- data, use `Image.extractMetadata()`. This is particularly useful for:
217
-
218
- - Reading EXIF data from large images or photos
219
- - Extracting metadata from images with unsupported compression
220
- - Building image catalogs or galleries
221
- - Processing metadata in batch operations
222
-
223
- ```typescript
224
- import { Image } from "@cross/image";
225
-
226
- // Extract metadata without decoding pixels
227
- const data = await Deno.readFile("large-photo.jpg");
228
- const metadata = await Image.extractMetadata(data);
229
-
230
- console.log(metadata?.cameraMake); // "Canon"
231
- console.log(metadata?.iso); // 800
232
- console.log(metadata?.exposureTime); // 0.004
233
-
234
- // Works with auto-detection
235
- const metadata2 = await Image.extractMetadata(data); // Detects JPEG
236
-
237
- // Or specify format explicitly
238
- const metadata3 = await Image.extractMetadata(data, "jpeg");
239
- ```
240
-
241
- This method is significantly faster than full decode when you only need
242
- metadata, as it:
243
-
244
- - Skips pixel data decompression
245
- - Only parses metadata chunks/markers
246
- - Returns `undefined` for unsupported formats
247
- - Works with JPEG, PNG, WebP, TIFF, HEIC, and AVIF formats
248
-
249
- ### Format-Specific Support
250
-
251
- Use `Image.getSupportedMetadata(format)` to check which fields are supported:
252
-
253
- ```typescript
254
- Image.getSupportedMetadata("jpeg"); // Full camera metadata + GPS (21 fields)
255
- Image.getSupportedMetadata("tiff"); // Comprehensive EXIF + GPS + InteropIFD (23+ fields)
256
- Image.getSupportedMetadata("png"); // DateTime, GPS, DPI, basic text (9 fields)
257
- Image.getSupportedMetadata("webp"); // Enhanced XMP + GPS (15 fields - includes camera metadata!)
258
- Image.getSupportedMetadata("heic"); // Full camera metadata + GPS (19 fields)
259
- Image.getSupportedMetadata("avif"); // Full camera metadata + GPS (19 fields)
260
- ```
261
-
262
- **Format Highlights:**
263
-
264
- - **JPEG**: Most comprehensive EXIF support, including all camera settings and
265
- GPS
266
- - **TIFF**: Full EXIF 3.0 support with IFD structure, InteropIFD compatibility
267
- - **WebP**: Enhanced XMP implementation with Dublin Core, EXIF, and TIFF
268
- namespaces
269
- - **PNG**: Basic EXIF support via eXIf chunk plus GPS coordinates
270
- - **HEIC**: Full EXIF metadata extraction including camera settings, GPS, and
271
- image info (runtime-dependent encoding)
272
- - **AVIF**: Full EXIF metadata extraction including camera settings, GPS, and
273
- image info (runtime-dependent encoding)
274
-
275
- ## Documentation
276
-
277
- - **[API Reference](https://cross-image.56k.guru/api/)** - Complete API
278
- documentation
279
- - **[Format Support](https://cross-image.56k.guru/formats/)** - Supported
280
- formats and specifications
281
- - **[Image Processing](https://cross-image.56k.guru/processing/)** - Filters,
282
- manipulation, and color adjustments
283
- - [Filters](https://cross-image.56k.guru/processing/filters/) - Blur, sharpen,
284
- and noise reduction
285
- - [Manipulation](https://cross-image.56k.guru/processing/manipulation/) -
286
- Resize, crop, composite, and draw
287
- - [Color Adjustments](https://cross-image.56k.guru/processing/color-adjustments/) -
288
- Brightness, contrast, saturation, and more
289
- - **[Examples](https://cross-image.56k.guru/examples/)** - Practical examples
290
- for common tasks
291
- - [Decoding & Encoding](https://cross-image.56k.guru/examples/decoding-encoding/) -
292
- Format-specific examples
293
- - [Using Filters](https://cross-image.56k.guru/examples/filters/) - Filter
294
- workflows and techniques
295
- - [Manipulation](https://cross-image.56k.guru/examples/manipulation/) -
296
- Resizing, cropping, and compositing
297
- - [Multi-Frame Images](https://cross-image.56k.guru/examples/multi-frame/) -
298
- Animated GIFs, APNGs, and TIFFs
299
- - **[JPEG Implementation](https://cross-image.56k.guru/implementation/jpeg-implementation/)** -
300
- Technical details for JPEG
301
- - **[WebP Implementation](https://cross-image.56k.guru/implementation/webp-implementation/)** -
302
- Technical details for WebP
303
- - **[TIFF Implementation](https://cross-image.56k.guru/implementation/tiff-implementation/)** -
304
- Technical details for TIFF
305
-
306
- ## Development
307
-
308
- ### Running Tests
309
-
310
- ```bash
311
- deno test -A
312
- ```
313
-
314
- ### Linting and Formatting
315
-
316
- ```bash
317
- deno fmt --check
318
- deno lint
319
- ```
320
-
321
- ### Type Checking
322
-
323
- ```bash
324
- deno check mod.ts
325
- ```
326
-
327
- ## License
328
-
329
- MIT License - see LICENSE file for details.
330
-
331
- ## Contributing
332
-
333
- 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 Deno, Node.js, and
4
+ Bun. Decode, encode, manipulate, and process images in multiple formats including PNG, JPEG, WebP,
5
+ GIF, and more—all without native dependencies.
6
+
7
+ 📚 **[Full Documentation](https://cross-image.56k.guru/)**
8
+
9
+ ## Features
10
+
11
+ - 🚀 **Pure JavaScript** - No native dependencies
12
+ - 🔌 **Pluggable formats** - Easy to extend with custom formats
13
+ - 📦 **Cross-runtime** - Works on Deno, Node.js (18+), and Bun
14
+ - 🎨 **Multiple formats** - PNG, APNG, JPEG, WebP, GIF, TIFF, BMP, ICO, DNG, PAM, PPM, PCX, ASCII,
15
+ HEIC, and AVIF support
16
+ - ✂️ **Image manipulation** - Resize, crop, composite, and more
17
+ - 🎛️ **Image processing** - Chainable filters including `brightness`, `contrast`, `saturation`,
18
+ `hue`, `exposure`, `blur`, `sharpen`, `sepia`, and more
19
+ - 🖌️ **Drawing operations** - Create, fill, and manipulate pixels
20
+ - 🧩 **Multi-frame** - Decode/encode animated GIFs, APNGs and multi-page TIFFs
21
+ - 🔧 **Simple API** - Easy to use, intuitive interface
22
+
23
+ ## Installation
24
+
25
+ ### Deno
26
+
27
+ ```ts
28
+ import { Image } from "jsr:@cross/image";
29
+ ```
30
+
31
+ ### Node.js
32
+
33
+ ```bash
34
+ npm install cross-image
35
+ ```
36
+
37
+ ```ts
38
+ import { Image } from "cross-image";
39
+ ```
40
+
41
+ ### Bun
42
+
43
+ ```bash
44
+ npm install cross-image
45
+ ```
46
+
47
+ ```ts
48
+ import { Image } from "cross-image";
49
+ ```
50
+
51
+ ## Quick Start
52
+
53
+ ### Deno
54
+
55
+ ```ts
56
+ import { Image } from "jsr:@cross/image";
57
+
58
+ // Decode an image (auto-detects format)
59
+ const data = await Deno.readFile("input.png");
60
+ const image = await Image.decode(data);
61
+
62
+ console.log(`Image size: ${image.width}x${image.height}`);
63
+
64
+ // Create a new blank image
65
+ const canvas = Image.create(800, 600, 255, 255, 255); // white background
66
+
67
+ // Composite the loaded image on top
68
+ canvas.composite(image, 50, 50);
69
+
70
+ // Apply image processing filters
71
+ canvas
72
+ .brightness(0.1)
73
+ .contrast(0.2)
74
+ .saturation(-0.1)
75
+ .blur(1)
76
+ .sharpen(0.3);
77
+
78
+ // Encode in a different format
79
+ const jpeg = await canvas.encode("jpeg");
80
+ await Deno.writeFile("output.jpg", jpeg);
81
+ ```
82
+
83
+ ### Node.js
84
+
85
+ ```ts
86
+ import { Image } from "cross-image";
87
+ import { readFile, writeFile } from "node:fs/promises";
88
+
89
+ // Read an image (auto-detects format)
90
+ const data = await readFile("input.png");
91
+ const image = await Image.decode(data);
92
+
93
+ console.log(`Image size: ${image.width}x${image.height}`);
94
+
95
+ // Resize the image
96
+ image.resize({ width: 800, height: 600 });
97
+
98
+ // Save in a different format
99
+ const jpeg = await image.encode("jpeg");
100
+ await writeFile("output.jpg", jpeg);
101
+ ```
102
+
103
+ ### Bun
104
+
105
+ ```ts
106
+ import { Image } from "cross-image";
107
+
108
+ // Read an image (auto-detects format)
109
+ const data = await Bun.file("input.png").arrayBuffer();
110
+ const image = await Image.decode(new Uint8Array(data));
111
+
112
+ console.log(`Image size: ${image.width}x${image.height}`);
113
+
114
+ // Resize the image and save
115
+ image.resize({ width: 800, height: 600 });
116
+ const jpeg = await image.encode("jpeg");
117
+ await Bun.write("output.jpg", jpeg);
118
+ ```
119
+
120
+ ## Supported Formats
121
+
122
+ | Format | Pure-JS | Notes |
123
+ | ------ | ------------------------- | ---------------------------------------------------------------------------------------------- |
124
+ | PNG | ✅ Full | Complete pure-JS implementation |
125
+ | APNG | ✅ Full | Animated PNG with multi-frame |
126
+ | BMP | Full | Complete pure-JS implementation |
127
+ | ICO | ✅ Full | Windows Icon format |
128
+ | GIF | ✅ Full | Animated GIF with multi-frame |
129
+ | DNG | ✅ Full | Linear DNG (Uncompressed RGBA) |
130
+ | PAM | ✅ Full | Netpbm PAM format |
131
+ | PPM | Full | Netpbm PPM format (P3/P6) |
132
+ | PCX | Full | ZSoft PCX (RLE compressed) |
133
+ | ASCII | ✅ Full | Text-based ASCII art |
134
+ | JPEG | ⚠️ Baseline & Progressive | Pure-JS baseline & progressive DCT: decode with spectral selection; encode with 2-scan (DC+AC) |
135
+ | WebP | ⚠️ Lossless | Pure-JS lossless VP8L |
136
+ | TIFF | ⚠️ Basic | Pure-JS uncompressed, LZW, PackBits, & Deflate; grayscale & RGB/RGBA |
137
+ | HEIC | 🔌 Runtime | Requires ImageDecoder/OffscreenCanvas API support |
138
+ | AVIF | 🔌 Runtime | Requires ImageDecoder/OffscreenCanvas API support |
139
+
140
+ See the [full format support documentation](https://cross-image.56k.guru/formats/) for detailed
141
+ compatibility information.
142
+
143
+ ## Advanced Usage
144
+
145
+ Most users should stick to the `Image` API (`Image.decode`, `image.encode`, etc.).
146
+
147
+ If you need to work with format handlers directly (e.g. `new PNGFormat()`) or register your own
148
+ `ImageFormat` implementation via `Image.registerFormat(...)`, see the API reference section
149
+ “Exported Format Classes”:
150
+
151
+ - https://cross-image.56k.guru/api/
152
+
153
+ ## JPEG Tolerant Decoding
154
+
155
+ The JPEG decoder includes a tolerant decoding mode (enabled by default) that gracefully handles
156
+ partially corrupted images or complex encoding patterns from mobile phone cameras. When enabled, the
157
+ decoder will continue processing even if some blocks fail to decode, filling failed blocks with
158
+ neutral values.
159
+
160
+ **Features:**
161
+
162
+ - **Enabled by default** - Handles real-world JPEGs from various devices
163
+ - **Progressive JPEG support** - Decodes both baseline and progressive JPEGs
164
+ - **Configurable** - Can be disabled for strict validation
165
+ - **Fault-tolerant** - Recovers partial image data instead of failing completely
166
+ - **Zero configuration** - Works automatically with the standard `Image.decode()` API
167
+
168
+ **When to use:**
169
+
170
+ - Mobile phone JPEGs with complex encoding patterns
171
+ - Progressive JPEG images from web sources
172
+ - Images from various camera manufacturers
173
+ - Partially corrupted JPEG files
174
+ - Production applications requiring maximum compatibility
175
+
176
+ **Example:**
177
+
178
+ ```typescript
179
+ import { Image } from "jsr:@cross/image";
180
+
181
+ const data = await Deno.readFile("mobile-photo.jpg");
182
+ // Default behavior - tolerant decoding enabled
183
+ const image = await Image.decode(data);
184
+
185
+ // Strict mode - fail fast on decode errors
186
+ const strictImage = await Image.decode(data, { tolerantDecoding: false });
187
+
188
+ // Optional: receive warnings during partial decode (pure-JS decoder paths)
189
+ const imageWithWarnings = await Image.decode(data, {
190
+ tolerantDecoding: true,
191
+ runtimeDecoding: "never",
192
+ onWarning: (message, details) => {
193
+ console.log(`JPEG Warning: ${message}`, details);
194
+ },
195
+ });
196
+ ```
197
+
198
+ **Note:** When using `Image.decode()`, the library automatically tries runtime-optimized decoders
199
+ (ImageDecoder API) first, falling back to the pure JS decoder with tolerant mode for maximum
200
+ compatibility.
201
+
202
+ ## Fault-Tolerant Decoding for Other Formats
203
+
204
+ In addition to JPEG, @cross/image provides fault-tolerant decoding for several other formats that
205
+ commonly encounter corruption or complex encoding patterns:
206
+
207
+ ### GIF Fault-Tolerant Decoding
208
+
209
+ The GIF decoder supports frame-level tolerance for animated GIFs. When enabled (default), corrupted
210
+ frames are skipped instead of causing complete decode failure.
211
+
212
+ **Features:**
213
+
214
+ - **Enabled by default** - Handles multi-frame GIFs with some corrupted frames
215
+ - **Frame-level recovery** - Skips bad frames, preserves good ones
216
+ - **LZW decompression errors** - Continues past compression errors
217
+
218
+ **Example:**
219
+
220
+ ```typescript
221
+ import { Image } from "jsr:@cross/image";
222
+
223
+ const data = await Deno.readFile("animated.gif");
224
+
225
+ // Tolerant mode (default) - skips corrupted frames
226
+ const tolerantFrames = await Image.decodeFrames(data);
227
+
228
+ // Strict mode - throws on first corrupted frame
229
+ const strictFrames = await Image.decodeFrames(data, {
230
+ tolerantDecoding: false,
231
+ });
232
+
233
+ // Optional: receive warnings when frames are skipped
234
+ const framesWithWarnings = await Image.decodeFrames(data, {
235
+ tolerantDecoding: true,
236
+ runtimeDecoding: "never",
237
+ onWarning: (message, details) => {
238
+ console.log(`GIF Warning: ${message}`, details);
239
+ },
240
+ });
241
+ ```
242
+
243
+ ### WebP Fault-Tolerant Decoding (VP8L Lossless)
244
+
245
+ The WebP VP8L (lossless) decoder supports pixel-level tolerance. When enabled (default), decoding
246
+ errors result in gray pixels for remaining data instead of complete failure.
247
+
248
+ **Features:**
249
+
250
+ - **Enabled by default** - Handles VP8L images with Huffman/LZ77 errors
251
+ - **Pixel-level recovery** - Fills remaining pixels with neutral gray
252
+ - **Huffman decode errors** - Continues past invalid codes
253
+
254
+ **Example:**
255
+
256
+ ```typescript
257
+ import { Image } from "jsr:@cross/image";
258
+
259
+ const data = await Deno.readFile("image.webp");
260
+
261
+ // Tolerant mode (default) - fills bad pixels with gray
262
+ const tolerantImage = await Image.decode(data);
263
+
264
+ // Strict mode - throws on first decode error
265
+ const strictImage = await Image.decode(data, { tolerantDecoding: false });
266
+
267
+ // Optional: receive warnings during partial decode
268
+ const imageWithWarnings = await Image.decode(data, {
269
+ tolerantDecoding: true,
270
+ runtimeDecoding: "never",
271
+ onWarning: (message, details) => {
272
+ console.log(`WebP Warning: ${message}`, details);
273
+ },
274
+ });
275
+ void imageWithWarnings;
276
+ ```
277
+
278
+ ### When to Use Fault-Tolerant Modes
279
+
280
+ **Use tolerant decoding (default) when:**
281
+
282
+ - Processing user-uploaded images from various sources
283
+ - Building production applications requiring maximum compatibility
284
+ - Handling images from mobile devices or cameras
285
+ - Recovering data from partially corrupted files
286
+ - Batch processing where some failures are acceptable
287
+
288
+ **Use strict decoding when:**
289
+
290
+ - Validating image file integrity
291
+ - Quality control in professional workflows
292
+ - Detecting file corruption explicitly
293
+ - Testing image encoder implementations
294
+
295
+ ### Warning Callbacks
296
+
297
+ Decoding APIs accept an optional `onWarning` callback that gets invoked when non-fatal issues occur
298
+ during decoding. This is useful for logging, monitoring, or debugging decoding issues without using
299
+ `console` methods.
300
+
301
+ **Example:**
302
+
303
+ ```typescript
304
+ import { Image } from "jsr:@cross/image";
305
+
306
+ const data = await Deno.readFile("input.webp");
307
+
308
+ const image = await Image.decode(data, {
309
+ tolerantDecoding: true,
310
+ runtimeDecoding: "never",
311
+ onWarning: (message, details) => {
312
+ // Log to your preferred logging system
313
+ myLogger.warn(message, details);
314
+ },
315
+ });
316
+ void image;
317
+ ```
318
+
319
+ The callback receives:
320
+
321
+ - `message`: A human-readable description of the warning
322
+ - `details`: Optional additional context (usually the error object)
323
+
324
+ ## Metadata Support
325
+
326
+ @cross/image provides comprehensive EXIF 3.0 compliant metadata support for image files, including
327
+ camera information, GPS coordinates, and InteropIFD compatibility markers.
328
+
329
+ ### Supported Metadata Fields
330
+
331
+ **Basic Metadata:**
332
+
333
+ - `title`, `description`, `author`, `copyright`
334
+ - `creationDate` - Date/time image was created
335
+
336
+ **Camera Settings (JPEG, TIFF, WebP via XMP):**
337
+
338
+ - `cameraMake`, `cameraModel` - Camera manufacturer and model
339
+ - `lensMake`, `lensModel` - Lens information
340
+ - `iso` - ISO speed rating
341
+ - `exposureTime` - Shutter speed in seconds
342
+ - `fNumber` - Aperture (f-number)
343
+ - `focalLength` - Focal length in mm
344
+ - `flash`, `whiteBalance` - Capture settings
345
+ - `orientation` - Image orientation (1=normal, 3=180°, 6=90°CW, 8=90°CCW)
346
+ - `software` - Software used
347
+ - `userComment` - User notes
348
+
349
+ **GPS Coordinates (All EXIF formats: JPEG, PNG, WebP, TIFF):**
350
+
351
+ - `latitude`, `longitude` - GPS coordinates in decimal degrees
352
+ - Full microsecond precision with DMS (degrees-minutes-seconds) conversion
353
+
354
+ **DPI (JPEG, PNG, TIFF):**
355
+
356
+ - `dpiX`, `dpiY` - Dots per inch for printing
357
+
358
+ ### EXIF 3.0 Specification Compliance
359
+
360
+ The library implements the EXIF 3.0 specification with:
361
+
362
+ - **50+ Exif Sub-IFD tags** for comprehensive camera metadata
363
+ - **30+ IFD0 tags** for image information
364
+ - **InteropIFD support** for format compatibility (R98/sRGB, R03/Adobe RGB, THM/thumbnail)
365
+ - **GPS IFD** with proper coordinate conversion
366
+ - All EXIF data types (BYTE, ASCII, SHORT, LONG, RATIONAL, etc.)
367
+
368
+ ### Example Usage
369
+
370
+ ```typescript
371
+ import { Image } from "jsr:@cross/image";
372
+
373
+ // Load an image
374
+ const data = await Deno.readFile("photo.jpg");
375
+ const image = await Image.decode(data);
376
+
377
+ // Set metadata
378
+ image.setMetadata({
379
+ author: "Jane Photographer",
380
+ copyright: "© 2024",
381
+ cameraMake: "Canon",
382
+ cameraModel: "EOS R5",
383
+ iso: 800,
384
+ exposureTime: 0.004, // 1/250s
385
+ fNumber: 2.8,
386
+ focalLength: 50,
387
+ });
388
+
389
+ // Set GPS coordinates
390
+ image.setPosition(40.7128, -74.0060); // NYC
391
+
392
+ // Check what metadata a format supports
393
+ const jpegSupports = Image.getSupportedMetadata("jpeg");
394
+ console.log(jpegSupports); // Includes ISO, camera info, GPS, etc.
395
+
396
+ // Save with metadata
397
+ const jpeg = await image.save("jpeg");
398
+ await Deno.writeFile("output.jpg", jpeg);
399
+
400
+ // Metadata is preserved on reload!
401
+ const loaded = await Image.decode(jpeg);
402
+ console.log(loaded.metadata?.cameraMake); // "Canon"
403
+ console.log(loaded.getPosition()); // { latitude: 40.7128, longitude: -74.0060 }
404
+ ```
405
+
406
+ ### Extracting Metadata Without Decoding
407
+
408
+ For quickly reading metadata from images without the overhead of decoding pixel data, use
409
+ `Image.extractMetadata()`. This is particularly useful for:
410
+
411
+ - Reading EXIF data from large images or photos
412
+ - Extracting metadata from images with unsupported compression
413
+ - Building image catalogs or galleries
414
+ - Processing metadata in batch operations
415
+
416
+ ```typescript
417
+ import { Image } from "jsr:@cross/image";
418
+
419
+ // Extract metadata without decoding pixels
420
+ const data = await Deno.readFile("large-photo.jpg");
421
+ const metadata = await Image.extractMetadata(data);
422
+
423
+ console.log(metadata?.cameraMake); // "Canon"
424
+ console.log(metadata?.iso); // 800
425
+ console.log(metadata?.exposureTime); // 0.004
426
+
427
+ // Works with auto-detection
428
+ const metadata2 = await Image.extractMetadata(data); // Detects JPEG
429
+
430
+ // Or specify format explicitly
431
+ const metadata3 = await Image.extractMetadata(data, "jpeg");
432
+ ```
433
+
434
+ This method is significantly faster than full decode when you only need metadata, as it:
435
+
436
+ - Skips pixel data decompression
437
+ - Only parses metadata chunks/markers
438
+ - Returns `undefined` for unsupported formats
439
+ - Works with JPEG, PNG, WebP, TIFF, HEIC, and AVIF formats
440
+
441
+ ### Format-Specific Support
442
+
443
+ Use `Image.getSupportedMetadata(format)` to check which fields are supported:
444
+
445
+ ```typescript
446
+ Image.getSupportedMetadata("jpeg"); // Full camera metadata + GPS (21 fields)
447
+ Image.getSupportedMetadata("tiff"); // Comprehensive EXIF + GPS + InteropIFD (23+ fields)
448
+ Image.getSupportedMetadata("png"); // DateTime, GPS, DPI, basic text (9 fields)
449
+ Image.getSupportedMetadata("webp"); // Enhanced XMP + GPS (15 fields - includes camera metadata!)
450
+ Image.getSupportedMetadata("heic"); // Full camera metadata + GPS (19 fields)
451
+ Image.getSupportedMetadata("avif"); // Full camera metadata + GPS (19 fields)
452
+ ```
453
+
454
+ **Format Highlights:**
455
+
456
+ - **JPEG**: Most comprehensive EXIF support, including all camera settings and GPS
457
+ - **TIFF**: Full EXIF 3.0 support with IFD structure, InteropIFD compatibility
458
+ - **WebP**: Enhanced XMP implementation with Dublin Core, EXIF, and TIFF namespaces
459
+ - **PNG**: Basic EXIF support via eXIf chunk plus GPS coordinates
460
+ - **HEIC**: Full EXIF metadata extraction including camera settings, GPS, and image info
461
+ (runtime-dependent encoding)
462
+ - **AVIF**: Full EXIF metadata extraction including camera settings, GPS, and image info
463
+ (runtime-dependent encoding)
464
+
465
+ ## Documentation
466
+
467
+ - **[API Reference](https://cross-image.56k.guru/api/)** - Complete API documentation
468
+ - **[Format Support](https://cross-image.56k.guru/formats/)** - Supported formats and specifications
469
+ - **[Image Processing](https://cross-image.56k.guru/processing/)** - Filters, manipulation, and
470
+ color adjustments
471
+ - [Filters](https://cross-image.56k.guru/processing/filters/) - Blur, sharpen, and noise reduction
472
+ - [Manipulation](https://cross-image.56k.guru/processing/manipulation/) - Resize, crop, composite,
473
+ and draw
474
+ - [Color Adjustments](https://cross-image.56k.guru/processing/color-adjustments/) - Brightness,
475
+ contrast, saturation, and more
476
+ - **[Examples](https://cross-image.56k.guru/examples/)** - Practical examples for common tasks
477
+ - [Decoding & Encoding](https://cross-image.56k.guru/examples/decoding-encoding/) -
478
+ Format-specific examples
479
+ - [Using Filters](https://cross-image.56k.guru/examples/filters/) - Filter workflows and
480
+ techniques
481
+ - [Manipulation](https://cross-image.56k.guru/examples/manipulation/) - Resizing, cropping, and
482
+ compositing
483
+ - [Multi-Frame Images](https://cross-image.56k.guru/examples/multi-frame/) - Animated GIFs, APNGs,
484
+ and TIFFs
485
+ - **[JPEG Implementation](https://cross-image.56k.guru/implementation/jpeg-implementation/)** -
486
+ Technical details for JPEG
487
+ - **[WebP Implementation](https://cross-image.56k.guru/implementation/webp-implementation/)** -
488
+ Technical details for WebP
489
+ - **[TIFF Implementation](https://cross-image.56k.guru/implementation/tiff-implementation/)** -
490
+ Technical details for TIFF
491
+
492
+ ## Development
493
+
494
+ ```bash
495
+ deno task precommit
496
+ ```
497
+
498
+ CI validates cross-runtime compatibility (Deno, Bun, Node). See CONTRIBUTING.md for contributor
499
+ workflow details.
500
+
501
+ ## License
502
+
503
+ MIT License - see LICENSE file for details.
504
+
505
+ ## Contributing
506
+
507
+ Contributions are welcome! Please feel free to submit a Pull Request.