cross-image 0.2.1 β†’ 0.2.3

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 (44) hide show
  1. package/README.md +160 -32
  2. package/esm/mod.d.ts +2 -1
  3. package/esm/mod.js +2 -1
  4. package/esm/src/formats/jpeg.d.ts +12 -1
  5. package/esm/src/formats/jpeg.js +633 -4
  6. package/esm/src/formats/png_base.d.ts +8 -0
  7. package/esm/src/formats/png_base.js +176 -3
  8. package/esm/src/formats/ppm.d.ts +50 -0
  9. package/esm/src/formats/ppm.js +242 -0
  10. package/esm/src/formats/tiff.d.ts +10 -1
  11. package/esm/src/formats/tiff.js +194 -44
  12. package/esm/src/formats/webp.d.ts +9 -2
  13. package/esm/src/formats/webp.js +211 -62
  14. package/esm/src/image.d.ts +81 -0
  15. package/esm/src/image.js +282 -5
  16. package/esm/src/types.d.ts +41 -1
  17. package/esm/src/utils/image_processing.d.ts +98 -0
  18. package/esm/src/utils/image_processing.js +440 -0
  19. package/esm/src/utils/metadata/xmp.d.ts +52 -0
  20. package/esm/src/utils/metadata/xmp.js +325 -0
  21. package/esm/src/utils/resize.d.ts +4 -0
  22. package/esm/src/utils/resize.js +74 -0
  23. package/package.json +1 -1
  24. package/script/mod.d.ts +2 -1
  25. package/script/mod.js +4 -2
  26. package/script/src/formats/jpeg.d.ts +12 -1
  27. package/script/src/formats/jpeg.js +633 -4
  28. package/script/src/formats/png_base.d.ts +8 -0
  29. package/script/src/formats/png_base.js +176 -3
  30. package/script/src/formats/ppm.d.ts +50 -0
  31. package/script/src/formats/ppm.js +246 -0
  32. package/script/src/formats/tiff.d.ts +10 -1
  33. package/script/src/formats/tiff.js +194 -44
  34. package/script/src/formats/webp.d.ts +9 -2
  35. package/script/src/formats/webp.js +211 -62
  36. package/script/src/image.d.ts +81 -0
  37. package/script/src/image.js +280 -3
  38. package/script/src/types.d.ts +41 -1
  39. package/script/src/utils/image_processing.d.ts +98 -0
  40. package/script/src/utils/image_processing.js +451 -0
  41. package/script/src/utils/metadata/xmp.d.ts +52 -0
  42. package/script/src/utils/metadata/xmp.js +333 -0
  43. package/script/src/utils/resize.d.ts +4 -0
  44. package/script/src/utils/resize.js +75 -0
package/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # @cross/image
2
2
 
3
3
  A pure JavaScript, dependency-free, cross-runtime image processing library for
4
- Deno, Node.js, and Bun.
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.
5
7
 
6
8
  πŸ“š **[Full Documentation](https://cross-image.56k.guru/)**
7
9
 
@@ -11,10 +13,11 @@ Deno, Node.js, and Bun.
11
13
  - πŸ”Œ **Pluggable formats** - Easy to extend with custom formats
12
14
  - πŸ“¦ **Cross-runtime** - Works on Deno, Node.js (18+), and Bun
13
15
  - 🎨 **Multiple formats** - PNG, APNG, JPEG, WebP, GIF, TIFF, BMP, ICO, DNG,
14
- PAM, PCX and ASCII support
16
+ PAM, PPM, PCX and ASCII support
15
17
  - βœ‚οΈ **Image manipulation** - Resize, crop, composite, and more
16
- - πŸŽ›οΈ **Image processing** - Chainable `brightness`, `contrast`, `saturation`,
17
- and `exposure` helpers
18
+ - πŸŽ›οΈ **Image processing** - Chainable filters including `brightness`,
19
+ `contrast`, `saturation`, `hue`, `exposure`, `blur`, `sharpen`, `sepia`, and
20
+ more
18
21
  - πŸ–ŒοΈ **Drawing operations** - Create, fill, and manipulate pixels
19
22
  - 🧩 **Multi-frame** - Decode/encode animated GIFs, APNGs and multi-page TIFFs
20
23
  - πŸ”§ **Simple API** - Easy to use, intuitive interface
@@ -30,21 +33,21 @@ import { Image } from "jsr:@cross/image";
30
33
  ### Node.js
31
34
 
32
35
  ```bash
33
- npx jsr add @cross/image
36
+ npm install cross-image
34
37
  ```
35
38
 
36
39
  ```ts
37
- import { Image } from "@cross/image";
40
+ import { Image } from "cross-image";
38
41
  ```
39
42
 
40
43
  ### Bun
41
44
 
42
45
  ```bash
43
- bunx jsr add @cross/image
46
+ npm install cross-image
44
47
  ```
45
48
 
46
49
  ```ts
47
- import { Image } from "@cross/image";
50
+ import { Image } from "cross-image";
48
51
  ```
49
52
 
50
53
  ## Quick Start
@@ -66,11 +69,13 @@ const canvas = Image.create(800, 600, 255, 255, 255); // white background
66
69
  // Composite the loaded image on top
67
70
  canvas.composite(image, 50, 50);
68
71
 
69
- // Apply image processing
72
+ // Apply image processing filters
70
73
  canvas
71
74
  .brightness(0.1)
72
75
  .contrast(0.2)
73
- .saturation(-0.1);
76
+ .saturation(-0.1)
77
+ .blur(1)
78
+ .sharpen(0.3);
74
79
 
75
80
  // Encode in a different format
76
81
  const jpeg = await canvas.encode("jpeg");
@@ -99,37 +104,160 @@ await writeFile("output.jpg", jpeg);
99
104
 
100
105
  ## Supported Formats
101
106
 
102
- | Format | Pure-JS | Notes |
103
- | ------ | ----------- | ------------------------------- |
104
- | PNG | βœ… Full | Complete pure-JS implementation |
105
- | APNG | βœ… Full | Animated PNG with multi-frame |
106
- | BMP | βœ… Full | Complete pure-JS implementation |
107
- | ICO | βœ… Full | Windows Icon format |
108
- | GIF | βœ… Full | Animated GIF with multi-frame |
109
- | DNG | βœ… Full | Linear DNG (Uncompressed RGBA) |
110
- | PAM | βœ… Full | Netpbm PAM format |
111
- | PCX | βœ… Full | ZSoft PCX (RLE compressed) |
112
- | ASCII | βœ… Full | Text-based ASCII art |
113
- | JPEG | ⚠️ Baseline | Pure-JS baseline DCT only |
114
- | WebP | ⚠️ Lossless | Pure-JS lossless VP8L |
115
- | TIFF | ⚠️ Basic | Pure-JS uncompressed + LZW |
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 |
116
122
 
117
123
  See the
118
- [full format support documentation](https://cross-image.56k.guru/formats.html)
119
- for detailed compatibility information.
124
+ [full format support documentation](https://cross-image.56k.guru/formats/) for
125
+ detailed compatibility information.
126
+
127
+ ## Metadata Support
128
+
129
+ @cross/image provides comprehensive EXIF 3.0 compliant metadata support for
130
+ image files, including camera information, GPS coordinates, and InteropIFD
131
+ compatibility markers.
132
+
133
+ ### Supported Metadata Fields
134
+
135
+ **Basic Metadata:**
136
+
137
+ - `title`, `description`, `author`, `copyright`
138
+ - `creationDate` - Date/time image was created
139
+
140
+ **Camera Settings (JPEG, TIFF, WebP via XMP):**
141
+
142
+ - `cameraMake`, `cameraModel` - Camera manufacturer and model
143
+ - `lensMake`, `lensModel` - Lens information
144
+ - `iso` - ISO speed rating
145
+ - `exposureTime` - Shutter speed in seconds
146
+ - `fNumber` - Aperture (f-number)
147
+ - `focalLength` - Focal length in mm
148
+ - `flash`, `whiteBalance` - Capture settings
149
+ - `orientation` - Image orientation (1=normal, 3=180Β°, 6=90Β°CW, 8=90Β°CCW)
150
+ - `software` - Software used
151
+ - `userComment` - User notes
152
+
153
+ **GPS Coordinates (All EXIF formats: JPEG, PNG, WebP, TIFF):**
154
+
155
+ - `latitude`, `longitude` - GPS coordinates in decimal degrees
156
+ - Full microsecond precision with DMS (degrees-minutes-seconds) conversion
157
+
158
+ **DPI (JPEG, PNG, TIFF):**
159
+
160
+ - `dpiX`, `dpiY` - Dots per inch for printing
161
+
162
+ ### EXIF 3.0 Specification Compliance
163
+
164
+ The library implements the EXIF 3.0 specification with:
165
+
166
+ - **50+ Exif Sub-IFD tags** for comprehensive camera metadata
167
+ - **30+ IFD0 tags** for image information
168
+ - **InteropIFD support** for format compatibility (R98/sRGB, R03/Adobe RGB,
169
+ THM/thumbnail)
170
+ - **GPS IFD** with proper coordinate conversion
171
+ - All EXIF data types (BYTE, ASCII, SHORT, LONG, RATIONAL, etc.)
172
+
173
+ ### Example Usage
174
+
175
+ ```typescript
176
+ import { Image } from "@cross/image";
177
+
178
+ // Load an image
179
+ const data = await Deno.readFile("photo.jpg");
180
+ const image = await Image.decode(data);
181
+
182
+ // Set metadata
183
+ image.setMetadata({
184
+ author: "Jane Photographer",
185
+ copyright: "Β© 2024",
186
+ cameraMake: "Canon",
187
+ cameraModel: "EOS R5",
188
+ iso: 800,
189
+ exposureTime: 0.004, // 1/250s
190
+ fNumber: 2.8,
191
+ focalLength: 50,
192
+ });
193
+
194
+ // Set GPS coordinates
195
+ image.setPosition(40.7128, -74.0060); // NYC
196
+
197
+ // Check what metadata a format supports
198
+ const jpegSupports = Image.getSupportedMetadata("jpeg");
199
+ console.log(jpegSupports); // Includes ISO, camera info, GPS, etc.
200
+
201
+ // Save with metadata
202
+ const jpeg = await image.save("jpeg");
203
+ await Deno.writeFile("output.jpg", jpeg);
204
+
205
+ // Metadata is preserved on reload!
206
+ const loaded = await Image.decode(jpeg);
207
+ console.log(loaded.metadata?.cameraMake); // "Canon"
208
+ console.log(loaded.getPosition()); // { latitude: 40.7128, longitude: -74.0060 }
209
+ ```
210
+
211
+ ### Format-Specific Support
212
+
213
+ Use `Image.getSupportedMetadata(format)` to check which fields are supported:
214
+
215
+ ```typescript
216
+ Image.getSupportedMetadata("jpeg"); // Full camera metadata + GPS (21 fields)
217
+ Image.getSupportedMetadata("tiff"); // Comprehensive EXIF + GPS + InteropIFD (23+ fields)
218
+ Image.getSupportedMetadata("png"); // DateTime, GPS, DPI, basic text (9 fields)
219
+ Image.getSupportedMetadata("webp"); // Enhanced XMP + GPS (15 fields - includes camera metadata!)
220
+ ```
221
+
222
+ **Format Highlights:**
223
+
224
+ - **JPEG**: Most comprehensive EXIF support, including all camera settings and
225
+ GPS
226
+ - **TIFF**: Full EXIF 3.0 support with IFD structure, InteropIFD compatibility
227
+ - **WebP**: Enhanced XMP implementation with Dublin Core, EXIF, and TIFF
228
+ namespaces
229
+ - **PNG**: Basic EXIF support via eXIf chunk plus GPS coordinates
120
230
 
121
231
  ## Documentation
122
232
 
123
- - **[API Reference](https://cross-image.56k.guru/api.html)** - Complete API
233
+ - **[API Reference](https://cross-image.56k.guru/api/)** - Complete API
124
234
  documentation
125
- - **[Examples](https://cross-image.56k.guru/examples.html)** - Usage examples
126
- for common tasks
127
- - **[Format Support](https://cross-image.56k.guru/formats.html)** - Supported
235
+ - **[Format Support](https://cross-image.56k.guru/formats/)** - Supported
128
236
  formats and specifications
129
- - **[JPEG Implementation](https://cross-image.56k.guru/implementation/jpeg-implementation.html)** -
237
+ - **[Image Processing](https://cross-image.56k.guru/processing/)** - Filters,
238
+ manipulation, and color adjustments
239
+ - [Filters](https://cross-image.56k.guru/processing/filters/) - Blur, sharpen,
240
+ and noise reduction
241
+ - [Manipulation](https://cross-image.56k.guru/processing/manipulation/) -
242
+ Resize, crop, composite, and draw
243
+ - [Color Adjustments](https://cross-image.56k.guru/processing/color-adjustments/) -
244
+ Brightness, contrast, saturation, and more
245
+ - **[Examples](https://cross-image.56k.guru/examples/)** - Practical examples
246
+ for common tasks
247
+ - [Decoding & Encoding](https://cross-image.56k.guru/examples/decoding-encoding/) -
248
+ Format-specific examples
249
+ - [Using Filters](https://cross-image.56k.guru/examples/filters/) - Filter
250
+ workflows and techniques
251
+ - [Manipulation](https://cross-image.56k.guru/examples/manipulation/) -
252
+ Resizing, cropping, and compositing
253
+ - [Multi-Frame Images](https://cross-image.56k.guru/examples/multi-frame/) -
254
+ Animated GIFs, APNGs, and TIFFs
255
+ - **[JPEG Implementation](https://cross-image.56k.guru/implementation/jpeg-implementation/)** -
130
256
  Technical details for JPEG
131
- - **[WebP Implementation](https://cross-image.56k.guru/implementation/webp-implementation.html)** -
257
+ - **[WebP Implementation](https://cross-image.56k.guru/implementation/webp-implementation/)** -
132
258
  Technical details for WebP
259
+ - **[TIFF Implementation](https://cross-image.56k.guru/implementation/tiff-implementation/)** -
260
+ Technical details for TIFF
133
261
 
134
262
  ## Development
135
263
 
package/esm/mod.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @module @cross/image
3
3
  *
4
4
  * A pure JavaScript, dependency-free, cross-runtime image processing library.
5
- * Supports decoding, resizing, and encoding common image formats (PNG, APNG, JPEG, WebP, GIF, TIFF, BMP, ICO, DNG, PAM, PCX).
5
+ * Supports decoding, resizing, and encoding common image formats (PNG, APNG, JPEG, WebP, GIF, TIFF, BMP, ICO, DNG, PAM, PPM, PCX).
6
6
  * Includes image processing capabilities like compositing, level adjustments, and pixel manipulation.
7
7
  *
8
8
  * @example
@@ -55,5 +55,6 @@ export { ICOFormat } from "./src/formats/ico.js";
55
55
  export { DNGFormat } from "./src/formats/dng.js";
56
56
  export { PAMFormat } from "./src/formats/pam.js";
57
57
  export { PCXFormat } from "./src/formats/pcx.js";
58
+ export { PPMFormat } from "./src/formats/ppm.js";
58
59
  export { ASCIIFormat } from "./src/formats/ascii.js";
59
60
  //# sourceMappingURL=mod.d.ts.map
package/esm/mod.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @module @cross/image
3
3
  *
4
4
  * A pure JavaScript, dependency-free, cross-runtime image processing library.
5
- * Supports decoding, resizing, and encoding common image formats (PNG, APNG, JPEG, WebP, GIF, TIFF, BMP, ICO, DNG, PAM, PCX).
5
+ * Supports decoding, resizing, and encoding common image formats (PNG, APNG, JPEG, WebP, GIF, TIFF, BMP, ICO, DNG, PAM, PPM, PCX).
6
6
  * Includes image processing capabilities like compositing, level adjustments, and pixel manipulation.
7
7
  *
8
8
  * @example
@@ -54,4 +54,5 @@ export { ICOFormat } from "./src/formats/ico.js";
54
54
  export { DNGFormat } from "./src/formats/dng.js";
55
55
  export { PAMFormat } from "./src/formats/pam.js";
56
56
  export { PCXFormat } from "./src/formats/pcx.js";
57
+ export { PPMFormat } from "./src/formats/ppm.js";
57
58
  export { ASCIIFormat } from "./src/formats/ascii.js";
@@ -1,4 +1,4 @@
1
- import type { ImageData, ImageFormat } from "../types.js";
1
+ import type { ImageData, ImageFormat, ImageMetadata } from "../types.js";
2
2
  /**
3
3
  * JPEG format handler
4
4
  * Implements a basic JPEG decoder and encoder
@@ -30,6 +30,17 @@ export declare class JPEGFormat implements ImageFormat {
30
30
  private decodeUsingRuntime;
31
31
  private parseJFIF;
32
32
  private parseEXIF;
33
+ private parseExifSubIFD;
34
+ private parseGPSIFD;
35
+ private readRational;
33
36
  private createEXIFData;
37
+ private createGPSIFD;
38
+ private createExifSubIFD;
39
+ private toRational;
40
+ private writeRational;
41
+ /**
42
+ * Get the list of metadata fields supported by JPEG format
43
+ */
44
+ getSupportedMetadata(): Array<keyof ImageMetadata>;
34
45
  }
35
46
  //# sourceMappingURL=jpeg.d.ts.map