catalogue / tools / Images / PNG to JPEG

Convert PNG to JPEG

To convert PNG to JPEG, send one POST to /v1/image-convert with the PNG 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

01Limits

LimitValue
Largest source file25 MB (26,214,400 bytes)
Timeout60 s
Source formatsAVIF, GIF, JPEG, PNG, SVG, TIFF, WebP
Output formatsJPEG, PNG, WebP
Option qualitydefault 80

02Example

A real PNG to JPEG run of image-convert.

Request
POST /v1/image-convert
content-type: application/json
payment-signature: <base64 x402 payload>

{
  "url": "https://grist.tools/samples/images/convert-gradient.png",
  "quality": 80,
  "format": "jpeg"
}
Response
200 OK
payment-response: <base64 settlement receipt>

{
  "source_url": "https://grist.tools/samples/images/convert-gradient.png",
  "source_format": "png",
  "format": "jpeg",
  "mime_type": "image/jpeg",
  "width": 32,
  "height": 32,
  "bytes": 373,
  "image_base64": "/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsj..."
}

Source file: images/convert-gradient.png, 1.8 KB (1,817 bytes). 32x32 PNG of a smooth two-axis gradient (red rises left to right, green top to bottom), built from raw pixels with the pinned PNG encoder. The request sets quality to 80. The recorded run returned 373 bytes of JPEG, 21% of the source size, with an image of 32x32 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: its IHDR chunk declares 32 by 32 pixels, 8-bit truecolour RGB and no interlacing. The chunks run IHDR, pHYs, IDAT and IEND. 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

PNG as a source

Every PNG opens with the eight-byte signature 89 50 4E 47 0D 0A 1A 0A. The format is lossless and can carry an alpha channel. image-convert matches all eight bytes before sharp is loaded, while the OCR detector settles for the first four. Both services then read the dimensions from the header without decoding the raster, and a file whose width times height exceeds the shared decoded-pixel budget is refused at that point. The check exists because a small, highly compressible PNG, such as a solid colour or a decompression bomb, can inflate to an enormous raster, and Tesseract's cost grows with the pixel count. Since PNG stores exact pixel values, a PNG source contributes no compression noise of its own; any loss in a converted file comes from the lossy target encoder.

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

CodeHTTP
invalid_input400
blocked_target403
unreachable_target424
upstream_timeout424
unsupported_content_type415
too_large413
unprocessable422
internal500

When each is raised, and what it means for payment: /docs/image-convert.

05Questions

What does it cost to convert PNG to JPEG?
$0.003 per call, paid in USDC on Base via x402.
How large can the PNG 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.

06Related