Convert SVG to JPEG
To convert SVG to JPEG, send one POST to /v1/image-convert with the SVG source and "format": "jpeg" in the body. Each call costs $0.003 in USDC on Base via x402, with no account and no API key. The source file can be up to 25 MB.
- Endpoint
POST /v1/image-convert- Price
- $0.003 per call
- Service
- image-convert
01Limits
| Limit | Value |
|---|---|
| Largest source file | 25 MB (26,214,400 bytes) |
| Timeout | 60 s |
| Source formats | AVIF, GIF, JPEG, PNG, SVG, TIFF, WebP |
| Output formats | JPEG, PNG, WebP |
| Option quality | default 80 |
02Example
A real SVG to JPEG run of image-convert.
POST /v1/image-convert
content-type: application/json
payment-signature: <base64 x402 payload>
{
"url": "https://grist.tools/samples/images/svg-badge.svg",
"quality": 80,
"format": "jpeg"
}200 OK
payment-response: <base64 settlement receipt>
{
"source_url": "https://grist.tools/samples/images/svg-badge.svg",
"source_format": "svg",
"format": "jpeg",
"mime_type": "image/jpeg",
"width": 64,
"height": 48,
"bytes": 1133,
"image_base64": "/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsj..."
}Source file: images/svg-badge.svg, 365 bytes. 64x48 geometric SVG badge (rounded card, circle, square and a rule, no text), so its raster carries no font-dependent pixels. The request sets quality to 80. The recorded run returned 1.1 KB (1,133 bytes) of JPEG, 3.1 times the source size, with an image of 64x48 pixels. Decoded, the JPEG in image_base64 opens with FF D8 FF DB 00 43 00 06 04 05 06 05.
In the sample itself, the root svg element sets width 64, height 48 and viewBox 0 0 64 48, and below it come 2 rect, 1 circle and 1 path elements. In the returned JPEG: the start-of-image marker is followed directly by a 67-byte quantisation table segment (FF DB), with no JFIF APP0 segment in between: table 0, 8-bit precision, first quantiser value 6.
03Format notes
SVG as a source
SVG is text, so recognition cannot rest on a binary signature. After an optional byte order mark and leading whitespace, the head of the document must open with an XML prolog that is followed by an svg element, an SVG doctype, a comment followed by an svg element, or the svg tag itself. An HTML page that merely mentions svg somewhere is refused. The dedicated svg-to-png renderer never resolves external references, since the libvips SVG loader does not fetch remote hrefs, and it rejects malformed markup instead of returning a partial image. Its density option drives the natural raster size proportionally. Through image-convert the document is rasterised without that option and then re-encoded at its intrinsic size. As vector content, an SVG can be rendered at a new resolution without resampling a stored bitmap.
JPEG as a target
image-convert writes JPEG through sharp with options pinned around the caller's quality value. mozjpeg is off, scans are baseline rather than progressive, chroma subsampling is fixed, coding is optimised, and trellis quantisation and overshoot deringing are both disabled. Fixing these settings means the same image, format and quality produce the same bytes on a given build, instead of drifting with a libvips default. The pixel grid is not resized; only codec and container change, and the response reports the width and height of the result. Because withMetadata is never called, EXIF and similar blocks are dropped. An animated input is opened with animation off, so its first frame is the one encoded. Video frames take another road: video-thumbnail decodes one picture and hands it to ffmpeg's mjpeg encoder, which streams it out through image2pipe.
Note: JPEG has no alpha channel, so any transparency in the source is lost.
04Errors
| Code | HTTP |
|---|---|
invalid_input | 400 |
blocked_target | 403 |
unreachable_target | 424 |
upstream_timeout | 424 |
unsupported_content_type | 415 |
too_large | 413 |
unprocessable | 422 |
internal | 500 |
When each is raised, and what it means for payment: /docs/image-convert.
05Questions
- What does it cost to convert SVG to JPEG?
- $0.003 per call, paid in USDC on Base via x402.
- How large can the SVG file be?
- Up to 25 MB (26,214,400 bytes). Past a limit the call answers too_large (413).
- What happens if the conversion fails?
- The tool answers with a typed JSON error from the errors table. Payment is settled only after the tool has produced its result; a call that fails inside the tool is never settled.