Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AI.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ You can use AI models from various providers to perform tasks such as chat, text
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.img2txt('https://cdn.handwrytten.com/www/2020/02/home-hero-photo2%402x.png').then(puter.print);
puter.ai.img2txt('https://assets.puter.site/letter.png').then(puter.print);
</script>
</body>
</html>
Expand Down
26 changes: 21 additions & 5 deletions src/AI/img2txt.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,40 @@ description: Extract text from images using OCR to read printed text, handwritin
platforms: [websites, apps, nodejs, workers]
---

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.
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.

## Syntax

```js
puter.ai.img2txt(image, testMode = false)
puter.ai.img2txt(image, options = {})
puter.ai.img2txt({ source: image, ...options })
```

## Parameters

#### `image` (String|File|Blob) (required)
#### `image` / `source` (String|File|Blob) (required)

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.
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: ... }`.

#### `testMode` (Boolean) (Optional)

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.

#### `options` (Object) (Optional)

An options object with the following properties:

- `provider` (String) (Optional) - Choose the OCR backend. Can be `aws-textract` or `mistral`. Defaults to `aws-textract`.
- `model` (String) (Optional) - Mistral OCR model to use. Defaults to `mistral-ocr-latest`.
- `pages` (Array) (Optional) - Limit processing to specific page numbers (multi-page PDFs).
- `includeImageBase64` (Boolean) (Optional) - Mistral-only: requests the base64 of cropped regions in the response.
- `imageLimit` (Number) (Optional) - Control how many images are analyzed per document (Mistral).
- `imageMinSize` (Number) (Optional) - Set minimum size for images to be analyzed (Mistral).
- `bboxAnnotationFormat` (String) (Optional) - Mistral: format for bounding-box annotations (e.g., `yolo`, `xyxy`).
- `documentAnnotationFormat` (String) (Optional) - Mistral: request document-level annotations/markdown variants.
- `testMode` (Boolean) (Optional) - Same as positional argument; also works inside the options object.

## Return value

A `Promise` that will resolve to a string containing the text contained in the image.
Expand All @@ -37,8 +53,8 @@ In case of an error, the `Promise` will reject with an error message.
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
puter.ai.img2txt('https://cdn.handwrytten.com/www/2020/02/home-hero-photo2%402x.png').then(puter.print);
puter.ai.img2txt('https://assets.puter.site/letter.png').then(puter.print);
</script>
</body>
</html>
```
```
37 changes: 36 additions & 1 deletion src/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,42 @@ ul code {
/* So our .anchor can be positioned absolutely */
}

.docs-content table {
width: 100%;
border-collapse: collapse;
margin: 24px 0;
font-size: 14px;
}

.docs-content table thead, .docs-content table tr:first-child {
background: #f5f6fb;
}

.docs-content table th,
.docs-content table td {
padding: 10px 14px;
border: 1px solid #e2e4ef;
text-align: left;
}

.docs-content table tbody tr:nth-child(even) {
background: #fbfbfe;
}

.dark-mode .docs-content table thead,
.dark-mode .docs-content table tr:first-child {
background: rgba(255,255,255,0.05);
}

.dark-mode .docs-content table tbody tr:nth-child(even) {
background: rgba(255,255,255,0.03);
}

.dark-mode .docs-content table th,
.dark-mode .docs-content table td {
border-color: rgba(255,255,255,0.08);
}

.anchored-heading:target {
background-color: #ffffbe;
}
Expand Down Expand Up @@ -1559,4 +1595,3 @@ footer .copyright-notice{
.platform-name {
font-weight: 500;
}

2 changes: 1 addition & 1 deletion src/playground/examples/ai-img2txt.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
puter.print(`Loading...`);

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