Skip to content

Commit 955a89d

Browse files
authored
Update img2txt docs and add table styles (#68)
* Update `img2txt` docs and add table styles Expanded the `img2txt` documentation to include new options for provider selection and advanced OCR features. * Update `img2txt` example image URLs
1 parent a6ccedd commit 955a89d

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

src/AI.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ You can use AI models from various providers to perform tasks such as chat, text
6363
<body>
6464
<script src="https://js.puter.com/v2/"></script>
6565
<script>
66-
puter.ai.img2txt('https://cdn.handwrytten.com/www/2020/02/home-hero-photo2%402x.png').then(puter.print);
66+
puter.ai.img2txt('https://assets.puter.site/letter.png').then(puter.print);
6767
</script>
6868
</body>
6969
</html>

src/AI/img2txt.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,40 @@ description: Extract text from images using OCR to read printed text, handwritin
44
platforms: [websites, apps, nodejs, workers]
55
---
66

7-
Given an image will return the text contained in the image. Also known as OCR (Optical Character Recognition), this API can be used to extract text from images of printed text, handwriting, or any other text-based content.
7+
Given an image will return the text contained in the image. Also known as OCR (Optical Character Recognition), this API can be used to extract text from images of printed text, handwriting, or any other text-based content. You can choose between AWS Textract (default) or Mistral’s OCR service when you need multilingual or richer annotation output.
88

99
## Syntax
1010

1111
```js
1212
puter.ai.img2txt(image, testMode = false)
13+
puter.ai.img2txt(image, options = {})
14+
puter.ai.img2txt({ source: image, ...options })
1315
```
1416

1517
## Parameters
1618

17-
#### `image` (String|File|Blob) (required)
19+
#### `image` / `source` (String|File|Blob) (required)
1820

19-
A string containing the URL, or path (on Puter) of the image you want to recognize, or a `File` or `Blob` object containing the image.
21+
A string containing the URL or Puter path of the image you want to recognize, or a `File`/`Blob` object containing the image. When calling with an options object, pass it as `{ source: ... }`.
2022

2123
#### `testMode` (Boolean) (Optional)
2224

2325
A boolean indicating whether you want to use the test API. Defaults to `false`. This is useful for testing your code without using up API credits.
2426

27+
#### `options` (Object) (Optional)
28+
29+
An options object with the following properties:
30+
31+
- `provider` (String) (Optional) - Choose the OCR backend. Can be `aws-textract` or `mistral`. Defaults to `aws-textract`.
32+
- `model` (String) (Optional) - Mistral OCR model to use. Defaults to `mistral-ocr-latest`.
33+
- `pages` (Array) (Optional) - Limit processing to specific page numbers (multi-page PDFs).
34+
- `includeImageBase64` (Boolean) (Optional) - Mistral-only: requests the base64 of cropped regions in the response.
35+
- `imageLimit` (Number) (Optional) - Control how many images are analyzed per document (Mistral).
36+
- `imageMinSize` (Number) (Optional) - Set minimum size for images to be analyzed (Mistral).
37+
- `bboxAnnotationFormat` (String) (Optional) - Mistral: format for bounding-box annotations (e.g., `yolo`, `xyxy`).
38+
- `documentAnnotationFormat` (String) (Optional) - Mistral: request document-level annotations/markdown variants.
39+
- `testMode` (Boolean) (Optional) - Same as positional argument; also works inside the options object.
40+
2541
## Return value
2642

2743
A `Promise` that will resolve to a string containing the text contained in the image.
@@ -37,8 +53,8 @@ In case of an error, the `Promise` will reject with an error message.
3753
<body>
3854
<script src="https://js.puter.com/v2/"></script>
3955
<script>
40-
puter.ai.img2txt('https://cdn.handwrytten.com/www/2020/02/home-hero-photo2%402x.png').then(puter.print);
56+
puter.ai.img2txt('https://assets.puter.site/letter.png').then(puter.print);
4157
</script>
4258
</body>
4359
</html>
44-
```
60+
```

src/assets/css/style.css

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,42 @@ ul code {
200200
/* So our .anchor can be positioned absolutely */
201201
}
202202

203+
.docs-content table {
204+
width: 100%;
205+
border-collapse: collapse;
206+
margin: 24px 0;
207+
font-size: 14px;
208+
}
209+
210+
.docs-content table thead, .docs-content table tr:first-child {
211+
background: #f5f6fb;
212+
}
213+
214+
.docs-content table th,
215+
.docs-content table td {
216+
padding: 10px 14px;
217+
border: 1px solid #e2e4ef;
218+
text-align: left;
219+
}
220+
221+
.docs-content table tbody tr:nth-child(even) {
222+
background: #fbfbfe;
223+
}
224+
225+
.dark-mode .docs-content table thead,
226+
.dark-mode .docs-content table tr:first-child {
227+
background: rgba(255,255,255,0.05);
228+
}
229+
230+
.dark-mode .docs-content table tbody tr:nth-child(even) {
231+
background: rgba(255,255,255,0.03);
232+
}
233+
234+
.dark-mode .docs-content table th,
235+
.dark-mode .docs-content table td {
236+
border-color: rgba(255,255,255,0.08);
237+
}
238+
203239
.anchored-heading:target {
204240
background-color: #ffffbe;
205241
}
@@ -1559,4 +1595,3 @@ footer .copyright-notice{
15591595
.platform-name {
15601596
font-weight: 500;
15611597
}
1562-

src/playground/examples/ai-img2txt.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
puter.print(`Loading...`);
77

88
// Extract text from an image
9-
puter.ai.img2txt('https://cdn.handwrytten.com/www/2020/02/home-hero-photo2%402x.png').then(puter.print);
9+
puter.ai.img2txt('https://assets.puter.site/letter.png').then(puter.print);
1010
</script>
1111
</body>
1212
</html>

0 commit comments

Comments
 (0)