mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Reconcile every tool page's parameters, defaults, and response shape against the tool's Zod settings schema and executionHint in code. Notable fixes: color-palette (add count + format params, hex output, median-cut algorithm), favicon (add 5 params, was documented as having none), qr-generate (add logoDataUri), convert (add ppm/eps/tga formats), video-loudnorm (-16 LUFS not -14), smart-crop (async 202 not sync 200), images-to-video (1080x1080 square), and several output-filename and behavior-note corrections. Also normalize API endpoint paths to /api/v1/tools/<id> (no modality segment) and standardize curl examples on the Docker API port 1349. Verified with a clean docs build.
3.5 KiB
3.5 KiB
description
| description |
|---|
| Convert images to base64 data URIs for embedding in HTML, CSS, and more. |
Image to Base64
Convert one or more images to base64-encoded strings and data URIs. Supports optional format conversion, quality control, and resizing. Useful for embedding images directly in HTML, CSS, JSON, or email templates.
API Endpoint
POST /api/v1/tools/image-to-base64
Accepts multipart form data with one or more image files and an optional JSON settings field.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| outputFormat | string | No | "original" |
Convert before encoding: original, jpeg, png, webp, avif, jxl |
| quality | number | No | 80 |
Output quality for lossy formats (1 to 100) |
| maxWidth | number | No | 0 |
Maximum width in pixels (0 = no resize, will not enlarge) |
| maxHeight | number | No | 0 |
Maximum height in pixels (0 = no resize, will not enlarge) |
Example Request
curl -X POST http://localhost:1349/api/v1/tools/image-to-base64 \
-H "Authorization: Bearer si_your-api-key" \
-F "file=@icon.png" \
-F 'settings={"outputFormat": "webp", "quality": 80, "maxWidth": 200}'
Multiple files:
curl -X POST http://localhost:1349/api/v1/tools/image-to-base64 \
-H "Authorization: Bearer si_your-api-key" \
-F "file=@icon1.png" \
-F "file=@icon2.png" \
-F "file=@icon3.png" \
-F 'settings={"outputFormat": "original"}'
Example Response
{
"results": [
{
"filename": "icon.png",
"mimeType": "image/webp",
"width": 200,
"height": 200,
"originalSize": 45000,
"encodedSize": 28800,
"overheadPercent": -36.0,
"base64": "UklGRlYAAABXRUJQ...",
"dataUri": "data:image/webp;base64,UklGRlYAAABXRUJQ..."
}
],
"errors": []
}
Response Fields
| Field | Type | Description |
|---|---|---|
| results | array | Successfully converted images |
| errors | array | Images that failed to process (with filename and error message) |
Result Object
| Field | Type | Description |
|---|---|---|
| filename | string | Original filename |
| mimeType | string | MIME type of the encoded output |
| width | number | Final width in pixels (after any resizing) |
| height | number | Final height in pixels (after any resizing) |
| originalSize | number | Original file size in bytes |
| encodedSize | number | Size of the base64 string in bytes |
| overheadPercent | number | Percentage size difference vs original (positive = larger, negative = smaller) |
| base64 | string | Raw base64-encoded image data |
| dataUri | string | Complete data URI ready for use in src attributes |
Notes
- Base64 encoding typically increases size by approximately 33% compared to the binary file. The
overheadPercentfield shows the actual difference. - When
outputFormatis"original", HEIC/HEIF files are converted to JPEG (since browsers cannot display HEIC in data URIs). - The
maxWidthandmaxHeightoptions resize usingfit: insidewithwithoutEnlargement, so images smaller than the specified dimensions are not upscaled. - Multiple files can be processed in a single request. Each file is processed independently, and failures do not prevent other files from succeeding.
- SVG files are passed through as
image/svg+xmlwithout re-encoding (unless a format conversion is requested). - This is a read-only endpoint. It does not produce a downloadable file or a
jobId. The base64 data is returned directly in the response body.