Convert SVG to PNG
To convert SVG to PNG, send one POST to /v1/svg-to-png with the SVG source. 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/svg-to-png- Price
- $0.003 per call
- Service
- svg-to-png
- Docs
- /docs/svg-to-png
Also offered by image-convert; this page uses svg-to-png.
01Limits
| Limit | Value |
|---|---|
| Largest source file | 25 MB (26,214,400 bytes) |
| Timeout | 60 s |
| Source formats | SVG |
| Output formats | PNG |
| Option density | default 96 |
02Example
A real SVG to PNG run of svg-to-png.
POST /v1/svg-to-png
content-type: application/json
payment-signature: <base64 x402 payload>
{
"url": "https://grist.tools/samples/images/svg-badge.svg",
"density": 192
}200 OK
payment-response: <base64 settlement receipt>
{
"source_url": "https://grist.tools/samples/images/svg-badge.svg",
"format": "png",
"width": 171,
"height": 128,
"bytes": 2021,
"image_base64": "iVBORw0KGgoAAAANSUhEUgAAAKsAAACACAYAAAB0g5nsAAAACXBIWXMAAB2HAAAd..."
}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 density to 192. The recorded run returned 2 KB (2,021 bytes) of PNG, 5.5 times the source size, with an image of 171x128 pixels. Decoded, the PNG in image_base64 opens with 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D (ASCII PNG).
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 PNG: its IHDR chunk declares 171 by 128 pixels, 8-bit truecolour RGB with alpha and no interlacing. The next chunk is pHYs.
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.
PNG as a target
PNG output is lossless, so image-convert ignores the quality value when PNG is requested. Its encoder options are pinned: the maximum zlib compression level, a fixed effort, adaptive filtering off, palette quantisation off and no interlacing, so identical pixels always deflate to identical bytes. Dimensions are kept and reported in the response, and metadata is stripped. Vector input takes a separate service: svg-to-png renders the document at a caller-set density, which drives the natural raster size, and an optional width or height fits the render inside that box with the lanczos3 kernel, keeping the aspect ratio, before the same pinned PNG options apply. video-thumbnail writes PNG by default through ffmpeg's png encoder; when a width is requested, the height follows the aspect ratio and is rounded to an even number.
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/svg-to-png.
05Questions
- What does it cost to convert SVG to PNG?
- $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.