imgcraft 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.
Files changed (2) hide show
  1. package/README.md +116 -56
  2. package/package.json +24 -6
package/README.md CHANGED
@@ -1,92 +1,152 @@
1
1
  <p align="center">
2
- <img src="https://imgcraft-docs.vercel.app/logo.png" height="96" alt="imgcraft" />
2
+ <img src="https://imgcraft-docs.vercel.app/logo.png" height="80" alt="imgcraft" />
3
3
  </p>
4
4
 
5
5
  <p align="center">
6
- <a href="https://www.npmjs.com/package/imgcraft"><img src="https://img.shields.io/npm/v/imgcraft.svg" alt="npm version" /></a>
7
- <a href="https://github.com/ajithonmain/imgcraft/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/imgcraft.svg" alt="license" /></a>
8
- <a href="https://github.com/ajithonmain/imgcraft/actions"><img src="https://img.shields.io/badge/tests-65%20passing-brightgreen.svg" alt="tests" /></a>
9
- <a href="https://www.npmjs.com/package/imgcraft"><img src="https://img.shields.io/npm/dm/imgcraft" alt="npm downloads" /></a>
6
+ <a href="https://www.npmjs.com/package/imgcraft"><img src="https://img.shields.io/npm/v/imgcraft.svg" alt="npm version"></a>
7
+ <a href="https://www.npmjs.com/package/imgcraft"><img src="https://img.shields.io/npm/dm/imgcraft.svg" alt="downloads"></a>
8
+ <a href="https://github.com/ajithonmain/imgcraft/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/imgcraft.svg" alt="license"></a>
9
+ <a href="https://github.com/ajithonmain/imgcraft/actions"><img src="https://img.shields.io/badge/tests-65%20passing-brightgreen.svg" alt="tests"></a>
10
10
  </p>
11
11
 
12
- <p align="center"><b>Chainable image transforms for Node.js and the browser — with AI ops built in.</b></p>
12
+ ---
13
13
 
14
- ## Install
14
+ Chainable image processing for Node.js and the browser — with AI ops built in.
15
+
16
+ imgcraft converts images between formats, resizes, crops, removes backgrounds, upscales, and more — via a fluent chainable API. It runs natively in Node.js using sharp, and in the browser via WebAssembly. A hosted REST API is also available at `https://imgcraft-api.imgcraft.workers.dev`.
17
+
18
+ ## Installation
15
19
 
16
20
  ```sh
17
21
  npm install imgcraft
18
22
  ```
19
23
 
20
- Node.js requires [sharp](https://sharp.pixelplumbing.com/) as an optional peer dep. Browser uses WASM — no extra install.
21
-
22
- ## Usage
24
+ ## Examples
23
25
 
24
26
  ```ts
25
27
  import { img, batch } from 'imgcraft'
26
28
 
27
- // Resize + remove background + convert — in one chain
29
+ // Resize and convert
28
30
  const buffer = await img('photo.jpg')
29
- .resize(800)
30
- .removeBackground()
31
+ .resize(800, 600)
31
32
  .webp({ quality: 85 })
32
33
  .toBuffer()
33
34
 
35
+ // Remove background (no API key needed — runs locally)
36
+ const buffer = await img('portrait.jpg')
37
+ .removeBackground()
38
+ .png()
39
+ .toBuffer()
40
+
41
+ // Chain multiple transforms
42
+ const buffer = await img('input.png')
43
+ .resize(1200)
44
+ .sharpen()
45
+ .removeBackground()
46
+ .upscale(2)
47
+ .webp({ quality: 90 })
48
+ .toBuffer()
49
+
34
50
  // Batch process with concurrency control
35
51
  await batch(['a.jpg', 'b.jpg', 'c.jpg'], { concurrency: 4 })
36
- .resize(1200)
52
+ .resize(800)
37
53
  .webp()
38
54
  .toDir('./output')
39
- ```
40
-
41
- ## Why imgcraft?
42
-
43
- | Feature | imgcraft | sharp |
44
- |---|---|---|
45
- | Chainable API | ✅ | ✅ |
46
- | Node.js | ✅ | ✅ |
47
- | Browser (WASM) | ✅ | ❌ |
48
- | AI background removal | ✅ | ❌ |
49
- | Smart crop | ✅ | ❌ |
50
- | AI upscaling | ✅ | ❌ |
51
- | Hosted REST API | ✅ | ❌ |
52
- | TypeScript strict | ✅ | ✅ |
53
-
54
- ## API
55
55
 
56
- ```ts
57
- img(input)
58
- .resize(width?, height?, options?)
59
- .crop(left, top, width, height)
60
- .rotate(angle)
61
- .flip() / .flop()
62
- .format('webp' | 'jpeg' | 'png' | 'avif')
63
- .quality(1-100)
64
- .blur(sigma?) / .sharpen() / .grayscale()
65
- .brightness(factor) / .contrast(factor) / .saturation(factor)
66
- .tint(color) / .negate()
67
- .composite(input, options?)
68
- .removeBackground() // AI — no API key needed
69
- .smartCrop(options?) // AI — subject-aware crop
70
- .upscale(2 | 4) // AI ESRGAN upscaling
71
- .meta() // read metadata
72
- .stripMeta() // strip EXIF
73
- .toBuffer() // Buffer (Node) / Uint8Array (browser)
74
- .toFile(path) // write to disk (Node)
75
- .toStream() // → ReadableStream
76
- .toDataURL() // base64 data URI (browser)
56
+ // Browser (WASM — same API)
57
+ const result = await img(file)
58
+ .resize(400)
59
+ .grayscale()
60
+ .toDataURL()
61
+
62
+ // Read metadata
63
+ const meta = await img('photo.jpg').meta()
64
+ // { width: 3024, height: 4032, format: 'jpeg', size: 3621944, hasAlpha: false }
65
+
66
+ // REST API
67
+ const form = new FormData()
68
+ form.append('image', file)
69
+ form.append('ops', JSON.stringify([
70
+ { op: 'resize', width: 800 },
71
+ { op: 'format', format: 'webp', quality: 85 }
72
+ ]))
73
+ const res = await fetch('https://imgcraft-api.imgcraft.workers.dev/transform', {
74
+ method: 'POST', body: form
75
+ })
76
+ const blob = await res.blob()
77
77
  ```
78
78
 
79
+ ## Supported operations
80
+
81
+ **Transforms**
82
+ - `resize(width?, height?, options?)` — fit modes: cover, contain, fill, inside, outside
83
+ - `crop(left, top, width, height)` — extract a region
84
+ - `rotate(angle)` — 0, 90, 180, 270 degrees
85
+ - `flip()` — vertical flip
86
+ - `flop()` — horizontal flip
87
+
88
+ **Colour**
89
+ - `grayscale()` — convert to greyscale
90
+ - `tint(colour)` — apply colour tint
91
+ - `negate()` — invert colours
92
+ - `brightness(factor)` — adjust brightness
93
+ - `contrast(factor)` — adjust contrast
94
+ - `saturation(factor)` — adjust saturation
95
+
96
+ **Filters**
97
+ - `blur(sigma?)` — Gaussian blur
98
+ - `sharpen(options?)` — unsharp mask
99
+ - `median(size?)` — median filter
100
+
101
+ **Format & output**
102
+ - `format(type)` — jpeg, png, webp, avif
103
+ - `quality(1–100)` — output quality
104
+ - `jpeg(options?)` — JPEG-specific options
105
+ - `png(options?)` — PNG-specific options
106
+ - `webp(options?)` — WebP-specific options
107
+ - `avif(options?)` — AVIF-specific options
108
+
109
+ **Compositing**
110
+ - `composite(input, options?)` — overlay/watermark (base64 data URI input)
111
+
112
+ **Metadata**
113
+ - `meta()` — read width, height, format, size, hasAlpha, channels
114
+ - `stripMeta()` — remove EXIF and ICC data
115
+
116
+ **AI operations** *(Node.js only — lazy loaded, no API key required)*
117
+ - `removeBackground()` — subject isolation via ONNX model
118
+ - `smartCrop(options?)` — subject-aware crop via TensorFlow coco-ssd
119
+ - `upscale(2 | 4)` — ESRGAN super-resolution upscaling
120
+
121
+ **Output**
122
+ - `toBuffer()` — `Buffer` (Node.js) / `Uint8Array` (browser)
123
+ - `toFile(path)` — write to disk (Node.js only)
124
+ - `toStream()` — `ReadableStream<Uint8Array>`
125
+ - `toDataURL()` — base64 data URI (browser)
126
+
127
+ **Batch**
128
+ - `batch(inputs[], options?)` — process multiple images
129
+ - `.toBuffers()` — array of results
130
+ - `.toDir(path)` — write all to directory
131
+ - `.toFiles(paths[])` — 1:1 path mapping
132
+
79
133
  ## REST API
80
134
 
81
135
  ```
82
- POST https://imgcraft-api.imgcraft.workers.dev/transform
83
- POST https://imgcraft-api.imgcraft.workers.dev/info
84
- GET https://imgcraft-api.imgcraft.workers.dev/health
136
+ POST https://imgcraft-api.imgcraft.workers.dev/transform # process image
137
+ POST https://imgcraft-api.imgcraft.workers.dev/info # read metadata
138
+ GET https://imgcraft-api.imgcraft.workers.dev/health # status
85
139
  ```
86
140
 
87
- ## Links
141
+ Rate limited to 60 requests per minute per IP. AI operations not available via REST API.
142
+
143
+ ## Documentation
144
+
145
+ Visit **[imgcraft-docs.vercel.app](https://imgcraft-docs.vercel.app)** for complete API documentation, guides, and a live playground.
146
+
147
+ ## Contributing
88
148
 
89
- **[Docs](https://imgcraft-docs.vercel.app)** · **[Playground](https://imgcraft-docs.vercel.app/playground)** · **[GitHub](https://github.com/ajithonmain/imgcraft)**
149
+ Issues and pull requests welcome at [github.com/ajithonmain/imgcraft](https://github.com/ajithonmain/imgcraft).
90
150
 
91
151
  ## License
92
152
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imgcraft",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Chainable image transform pipeline — Node + Browser WASM",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -11,16 +11,34 @@
11
11
  "keywords": [
12
12
  "image",
13
13
  "image-processing",
14
+ "image-resize",
15
+ "image-compression",
14
16
  "sharp",
15
- "wasm",
16
- "resize",
17
+ "sharp-alternative",
17
18
  "webp",
18
19
  "avif",
19
- "pipeline",
20
+ "jpeg",
21
+ "png",
20
22
  "background-removal",
21
- "ai",
23
+ "remove-background",
24
+ "ai-image",
25
+ "upscale",
26
+ "smart-crop",
27
+ "wasm",
22
28
  "browser",
23
- "node"
29
+ "node",
30
+ "pipeline",
31
+ "chainable",
32
+ "thumbnail",
33
+ "crop",
34
+ "rotate",
35
+ "blur",
36
+ "watermark",
37
+ "batch",
38
+ "typescript",
39
+ "esm",
40
+ "image-transform",
41
+ "image-optimization"
24
42
  ],
25
43
  "type": "module",
26
44
  "main": "./dist/index.js",