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.
- package/README.md +160 -32
- package/esm/mod.d.ts +2 -1
- package/esm/mod.js +2 -1
- package/esm/src/formats/jpeg.d.ts +12 -1
- package/esm/src/formats/jpeg.js +633 -4
- package/esm/src/formats/png_base.d.ts +8 -0
- package/esm/src/formats/png_base.js +176 -3
- package/esm/src/formats/ppm.d.ts +50 -0
- package/esm/src/formats/ppm.js +242 -0
- package/esm/src/formats/tiff.d.ts +10 -1
- package/esm/src/formats/tiff.js +194 -44
- package/esm/src/formats/webp.d.ts +9 -2
- package/esm/src/formats/webp.js +211 -62
- package/esm/src/image.d.ts +81 -0
- package/esm/src/image.js +282 -5
- package/esm/src/types.d.ts +41 -1
- package/esm/src/utils/image_processing.d.ts +98 -0
- package/esm/src/utils/image_processing.js +440 -0
- package/esm/src/utils/metadata/xmp.d.ts +52 -0
- package/esm/src/utils/metadata/xmp.js +325 -0
- package/esm/src/utils/resize.d.ts +4 -0
- package/esm/src/utils/resize.js +74 -0
- package/package.json +1 -1
- package/script/mod.d.ts +2 -1
- package/script/mod.js +4 -2
- package/script/src/formats/jpeg.d.ts +12 -1
- package/script/src/formats/jpeg.js +633 -4
- package/script/src/formats/png_base.d.ts +8 -0
- package/script/src/formats/png_base.js +176 -3
- package/script/src/formats/ppm.d.ts +50 -0
- package/script/src/formats/ppm.js +246 -0
- package/script/src/formats/tiff.d.ts +10 -1
- package/script/src/formats/tiff.js +194 -44
- package/script/src/formats/webp.d.ts +9 -2
- package/script/src/formats/webp.js +211 -62
- package/script/src/image.d.ts +81 -0
- package/script/src/image.js +280 -3
- package/script/src/types.d.ts +41 -1
- package/script/src/utils/image_processing.d.ts +98 -0
- package/script/src/utils/image_processing.js +451 -0
- package/script/src/utils/metadata/xmp.d.ts +52 -0
- package/script/src/utils/metadata/xmp.js +333 -0
- package/script/src/utils/resize.d.ts +4 -0
- 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
|
|
17
|
-
|
|
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
|
-
|
|
36
|
+
npm install cross-image
|
|
34
37
|
```
|
|
35
38
|
|
|
36
39
|
```ts
|
|
37
|
-
import { Image } from "
|
|
40
|
+
import { Image } from "cross-image";
|
|
38
41
|
```
|
|
39
42
|
|
|
40
43
|
### Bun
|
|
41
44
|
|
|
42
45
|
```bash
|
|
43
|
-
|
|
46
|
+
npm install cross-image
|
|
44
47
|
```
|
|
45
48
|
|
|
46
49
|
```ts
|
|
47
|
-
import { Image } from "
|
|
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
|
-
|
|
|
112
|
-
|
|
|
113
|
-
|
|
|
114
|
-
|
|
|
115
|
-
|
|
|
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
|
|
119
|
-
|
|
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
|
|
233
|
+
- **[API Reference](https://cross-image.56k.guru/api/)** - Complete API
|
|
124
234
|
documentation
|
|
125
|
-
- **[
|
|
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
|
-
- **[
|
|
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
|
|
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
|