Skip to content
pdfconversionapi

JPG to PNM API

POST a JPEG to /v2/convert/jpg/to/pnm and the decoded photo comes back as a portable anymap: a 15-byte text header followed by raw RGB bytes. The header is binary PPM, P6, then the width, height and 255; ColorSpace=gray switches to a one-channel P5 graymap.

Endpoint
POST /v2/convert/jpg/to/pnm
Accepts
jpg
Sample timing
1 ms median of 5 runsHow we measure
Request size
Up to 10 MB on the Free plan or 100 MB on paid plans, all files together

Request and response

Every sample below ran against the API before this page was published. Set PDFCONVERSIONAPI_KEY to your key and run it as is.

curl -sS -X POST \
  https://api.pdfconversionapi.com/v2/convert/jpg/to/pnm \
  -H "Authorization: Bearer $PDFCONVERSIONAPI_KEY" \
  -F File=@trailhead-sign.jpg \
  -o response.json

# FileData is base64. Save the first file in converted/,
# or print the JSON error.
if jq -e '.Files' response.json > /dev/null; then
  mkdir -p converted
  name=$(jq -r '.Files[0].FileName' response.json)
  jq -r '.Files[0].FileData' response.json \
    | base64 --decode > "converted/$name"
else
  cat response.json
fi
200 OK1 ms median1 file, 352 KB
{
  "ConversionCost": 1,
  "ConversionTime": 0.001,
  "Files": [
    {
      "FileName": "trailhead-sign.pnm",
      "FileExt": "pnm",
      "FileSize": 360015,
      "FileData": "UDYKNDAwIDMwMCAyNTUKTYG9…"
    }
  ]
}

Response from our test run on 2026-11-03. ConversionTime shows the median of 5 runs. FileData is shortened here; the real response carries the whole file as base64.

The sample, converted

The same file the code sends. Download the input and the output and compare them yourself.

First page of trailhead-sign.pnm, rendered by the API
Input
trailhead-sign.jpg (25 KB)
Output
trailhead-sign.pnm (352 KB)
Source
A drawn mountain trailhead with a wooden sign and a QR code, made by us for these pages and saved at JPEG quality 92 with an EXIF block, an sRGB color profile and 300 dpi. (CC0-1.0). How it was made
Made by
2026-11-04, API build 9eeeb0640aba

Parameters

Send these as form fields next to the file. Names are case-insensitive. If you set one of the documented options below that we don't support yet, the request fails with a 400 that names it instead of returning a file made without it.

ParameterWhat it does
ImageWidthintegerWidth of the pixel array. 200 gives a 200 × 150 file of exactly 200 × 150 × 3 + 15 = 90,015 bytes.Values: 1–20000
ImageHeightintegerHeight of the array, width following the 4:3 photo. With ImageWidth it becomes a bounding box.Values: 1–20000
ScaleProportionsboolean, default truefalse with both dimensions gives exactly that grid, which suits models that take a fixed input size, at the cost of stretching.
ScaleIfLargerboolean, default falsetrue never enlarges; an 800 px request keeps the 400 × 300 array (otherwise 1,440,015 bytes).
ScaleImageboolean, default truefalse takes the top-left ImageWidth × ImageHeight region without resampling.
ImageInterpolationboolean, default falseAccepted either way; resampling is always Lanczos3.
ImageResolutionintegerAccepted for ConvertAPI compatibility, but the format has nowhere to store it; the bytes don't change.Values: 10–800
ColorSpaceenum, default defaultgray writes a one-channel P5 graymap, a third of the size (120,015 bytes for the sample); monochrome does the same with only the values 0 and 255.Values: default, rgb, gray, monochrome; cmyk refused
FileNamestringBase name; the extension is always .pnm.
StoreFileboolean, default falsetrue returns Files[].Url for 3 hours instead of inline data.

What carries over, and what doesn't

Kept

  • The decoded pixels exactly: the file matched our own JPEG decode of the sample on every pixel
  • 8 bits per channel (maximum value 255)
  • Size and shape, unless you ask for a resize
  • The upright view of phone photos: a 300 × 200 test photo tagged EXIF Orientation 6 came back as a 200 × 300 file, turned as the tag says

Lost or not yet supported

  • Compression. The file is 360,015 bytes for a 25,110-byte JPEG: 120,000 pixels at 3 bytes, plus the 15-byte header.
  • Grayscale as one channel by default: a gray JPEG comes out as a three-channel P6 file (360,015 bytes for a 400 × 300 test) unless you send ColorSpace=gray.
  • EXIF, the sRGB profile and the 300 dpi value.

Limits

  • One JPEG per call.
  • Upload limit 10 MB on the Free plan or 100 MB on paid plans.
  • 100,000,000 pixels per image; larger files get 413.
  • 1 to 20,000 px per side when resizing.
  • 120 seconds per conversion.

Where teams use it

Pixels for scripts without an image library

Read P6, the width, the height and 255, skip one whitespace byte, then read width × height × 3 bytes. A JPEG decoded by the API arrives in a form a shell script, a microcontroller loader or a numerical script can read directly.

Fixed-size inputs for vision experiments

Resize and decode in one request (ImageWidth=224, ImageHeight=224, ScaleProportions=false) to get a raw RGB grid of the size a model expects: 150,543 bytes for 224 × 224.

Questions

Is this PPM (P6) or something else?

It is binary PPM. The header reads P6, 400 300 and 255, one item per line, 15 bytes in all for the sample, and the RGB bytes follow. With ColorSpace=gray or monochrome the file is a P5 graymap with one byte per pixel instead.

Does a gray JPEG give a gray file?

Only when you ask. A gray test JPEG came back as a 360,015-byte P6 file with three equal channels. Send ColorSpace=gray for a P5 graymap: the sample becomes 120,015 bytes with the same gray values the gray PNG route gives.

Why doesn't ImageQuality change anything?

The file isn't compressed, so there is nothing to tune. ConvertAPI doesn't document ImageQuality for JPG to PNM, so the API ignores it rather than returning an error.

How big will the file be?

Width × height × 3 bytes plus a short header, 15 bytes for the 400 × 300 sample. A 12 MP photo is roughly 36 MB, so resize first if you don't need every pixel.

Convert your first JPG file in a minute.