@mdgate/image 0.6.7 → 0.6.9
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 +163 -6
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,18 +1,175 @@
|
|
|
1
1
|
# @mdgate/image
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Convert images to Markdown in TypeScript.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[`@mdgate/image`](https://github.com/mdgate/converters/tree/main/packages/image) handles JPEG, PNG, WebP, GIF, TIFF, HEIC, BMP, SVG, and gzip SVG (`.svgz`).
|
|
6
|
+
|
|
7
|
+
SVG is converted locally. Raster formats need a vision callback you provide. They are not registered by `all()`.
|
|
8
|
+
|
|
9
|
+
Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @mdgate/image
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## SVG, locally
|
|
18
|
+
|
|
19
|
+
`toMarkdown` on this package is the local SVG converter.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { toMarkdown } from '@mdgate/image';
|
|
23
|
+
|
|
24
|
+
const markdown = await toMarkdown(bytes);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
No Python, native addons, WASM, or vision API is required for SVG.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Raster images
|
|
32
|
+
|
|
33
|
+
Raster images are a different problem from DOCX or PDF. mdgate does not pick an OCR vendor.
|
|
34
|
+
|
|
35
|
+
Connect the model your application already uses:
|
|
6
36
|
|
|
7
37
|
```ts
|
|
8
38
|
import { create } from '@mdgate/core';
|
|
9
|
-
import { image
|
|
10
|
-
import { pdf } from '@mdgate/pdf';
|
|
39
|
+
import { image } from '@mdgate/image';
|
|
11
40
|
import { ai } from '@mdgate/ai';
|
|
41
|
+
import { pdf } from '@mdgate/pdf';
|
|
42
|
+
|
|
43
|
+
const media = ai({
|
|
44
|
+
baseURL: 'https://api.example.com/v1',
|
|
45
|
+
apiKey: process.env.API_KEY!,
|
|
46
|
+
model: 'your-vision-model',
|
|
47
|
+
});
|
|
12
48
|
|
|
13
|
-
const
|
|
49
|
+
const read = create([
|
|
14
50
|
pdf(),
|
|
51
|
+
image(media.convertImage),
|
|
52
|
+
]);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Or pass any `(input) => markdown` function. The callback receives `{ bytes, mime, page }`.
|
|
56
|
+
|
|
57
|
+
`image()` is not included in `all()`. `svg()` is.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Why [`@mdgate/image`](https://github.com/mdgate/converters/tree/main/packages/image)
|
|
62
|
+
|
|
63
|
+
This package exists so images can join the same converter registry as documents.
|
|
64
|
+
|
|
65
|
+
* **Pure TypeScript**
|
|
66
|
+
* **SVG → Markdown locally**
|
|
67
|
+
* **Raster images via your callback**
|
|
68
|
+
* **No Python runtime**
|
|
69
|
+
* **No native addons**
|
|
70
|
+
* **No WASM runtime**
|
|
71
|
+
* **Zero third-party runtime dependencies in this package**
|
|
72
|
+
* **Detects common image types from their contents, not only the filename**
|
|
73
|
+
|
|
74
|
+
When composed with [`@mdgate/pdf`](https://github.com/mdgate/converters/tree/main/packages/pdf), embedded PDF images can be handed back into this converter.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## What it extracts
|
|
79
|
+
|
|
80
|
+
**SVG / SVGZ:**
|
|
81
|
+
|
|
82
|
+
* titles and visible text from the SVG
|
|
83
|
+
|
|
84
|
+
**Raster (JPEG, PNG, WebP, GIF, TIFF, HEIC, BMP):**
|
|
85
|
+
|
|
86
|
+
* whatever Markdown your callback returns
|
|
87
|
+
|
|
88
|
+
mdgate does not silently send every image to a remote model. You register the callback.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Node.js
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { readFile } from 'node:fs/promises';
|
|
96
|
+
import { create } from '@mdgate/core';
|
|
97
|
+
import { image } from '@mdgate/image';
|
|
98
|
+
|
|
99
|
+
const read = create([
|
|
100
|
+
image(async (input) => {
|
|
101
|
+
// Send input.bytes to the vision model you already use.
|
|
102
|
+
return '...';
|
|
103
|
+
}),
|
|
104
|
+
]);
|
|
105
|
+
|
|
106
|
+
const bytes = new Uint8Array(await readFile('scan.png'));
|
|
107
|
+
const markdown = await read(bytes, { path: 'scan.png' });
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Browser
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { create } from '@mdgate/core';
|
|
116
|
+
import { image, svg } from '@mdgate/image';
|
|
117
|
+
|
|
118
|
+
const read = create([
|
|
15
119
|
svg(),
|
|
16
|
-
image(
|
|
120
|
+
image(convertImage),
|
|
121
|
+
]);
|
|
122
|
+
|
|
123
|
+
const file = input.files![0];
|
|
124
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
125
|
+
const markdown = await read(bytes, { path: file.name });
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Compose it with other file readers
|
|
131
|
+
|
|
132
|
+
[`@mdgate/image`](https://github.com/mdgate/converters/tree/main/packages/image) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { create } from '@mdgate/core';
|
|
136
|
+
import { image } from '@mdgate/image';
|
|
137
|
+
import { pdf } from '@mdgate/pdf';
|
|
138
|
+
|
|
139
|
+
const read = create([
|
|
140
|
+
pdf(),
|
|
141
|
+
image(convertImage),
|
|
17
142
|
]);
|
|
18
143
|
```
|
|
144
|
+
|
|
145
|
+
The application still uses one reading interface while each format remains independently installable.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Need more than images?
|
|
150
|
+
|
|
151
|
+
If your application needs to read many different file types, use the complete converter set:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
npm install @mdgate/converters
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import { toMarkdown } from '@mdgate/converters';
|
|
159
|
+
|
|
160
|
+
const markdown = await toMarkdown(bytes, {
|
|
161
|
+
path: filename,
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Raster image conversion still needs `image()` composed on top of `all()`, because `all()` does not register it.
|
|
166
|
+
|
|
167
|
+
[`@mdgate/image`](https://github.com/mdgate/converters/tree/main/packages/image) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
|
|
168
|
+
|
|
169
|
+
For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/image",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "mdgate image converter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://
|
|
7
|
+
"homepage": "https://convert.mdgate.dev",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/mdgate/converters.git",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"prepublishOnly": "bun run build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@mdgate/core": "0.6.
|
|
32
|
-
"@mdgate/document": "0.6.
|
|
33
|
-
"@mdgate/utils": "0.6.
|
|
31
|
+
"@mdgate/core": "0.6.9",
|
|
32
|
+
"@mdgate/document": "0.6.9",
|
|
33
|
+
"@mdgate/utils": "0.6.9"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|