HEIC to PNM API
POST a HEIC to /v2/convert/heic/to/pnm and get the decoded photo as uncompressed RGB bytes behind a text header. The header is the classic binary PPM form, P6 followed by the width, height and 255; the 400 × 300 sample makes a 360,015-byte file.
- Endpoint
- POST /v2/
convert/ heic/ to/ pnm - Accepts
- heic
- Sample timing
- 25 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/heic/to/pnm \
-H "Authorization: Bearer $PDFCONVERSIONAPI_KEY" \
-F File=@harbor-dusk.heic \
-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
fiimport base64
import os
import requests
key = os.environ["PDFCONVERSIONAPI_KEY"]
response = requests.post(
"https://api.pdfconversionapi.com/v2/convert/heic/to/pnm",
headers={"Authorization": f"Bearer {key}"},
files=[("File", open("harbor-dusk.heic", "rb"))],
timeout=180,
)
result = response.json()
if not response.ok:
raise SystemExit(f"{result['Code']}: {result['Message']}")
os.makedirs("converted", exist_ok=True)
for file in result["Files"]:
path = os.path.join("converted", file["FileName"])
with open(path, "wb") as out:
out.write(base64.b64decode(file["FileData"]))
print(path, file["FileSize"], "bytes")
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
const form = new FormData();
const file = "harbor-dusk.heic";
form.append("File", new Blob([await readFile(file)]), file);
const url = "https://api.pdfconversionapi.com/v2/convert/heic/to/pnm";
const key = process.env.PDFCONVERSIONAPI_KEY;
const response = await fetch(url, {
method: "POST",
headers: { Authorization: `Bearer ${key}` },
body: form,
});
const result = await response.json();
if (!response.ok) {
throw new Error(`${result.Code}: ${result.Message}`);
}
await mkdir("converted", { recursive: true });
for (const file of result.Files) {
const path = join("converted", file.FileName);
await writeFile(path, Buffer.from(file.FileData, "base64"));
console.log(path, file.FileSize, "bytes");
}
{
"ConversionCost": 1,
"ConversionTime": 0.025,
"Files": [
{
"FileName": "harbor-dusk.pnm",
"FileExt": "pnm",
"FileSize": 360015,
"FileData": "UDYKNDAwIDMwMCAyNTUKGCFY…"
}
]
}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.

- Input
- harbor-dusk.heic (22 KB)
- Output
- harbor-dusk.pnm (352 KB)
- Source
- A harbor at dusk that we drew ourselves, saved as a 400 x 300 HEIC stored sideways with a rotation flag and made-up camera and GPS tags. (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.
| Parameter | What it does |
|---|---|
ImageWidthinteger | Scales the photo first; 200 gives a 90,015-byte file whose header reads 200 150.Values: 1–20000 |
ImageHeightinteger | Target height, or a bounding box together with ImageWidth.Values: 1–20000 |
ScaleProportionsboolean, default true | false allows both sizes to distort the photo. |
ScaleIfLargerboolean, default false | true prevents enlargement past the photo's own size. |
ScaleImageboolean, default true | false takes a top-left crop of the requested size. |
AlphaColorstring, default white | Background for transparent pixels, since the file has three channels. An opaque photo like the sample is unchanged; a HEIC with an alpha plane is blended onto this color.Values: #RRGGBB, R,G,B or white, black, red, green, blue, gray |
BackgroundColorstring, default white | Used as the background when AlphaColor is not sent. |
ColorSpaceenum, default default | gray and monochrome write a one-channel graymap instead: the header starts with P5 and the full-size file is 120,015 bytes. monochrome holds only 0 and 255.Values: default, rgb, gray, monochrome |
FileNamestring | Base name of the .pnm. |
StoreFileboolean, default false | true keeps the file for 3 hours and returns a link. |
What carries over, and what doesn't
Kept
- Every decoded pixel: reading the file back through our PNM to PNG route gave a PNG byte-identical to our HEIC to PNG output
- The upright view, from the rotation flag in the HEIC
- A plain layout: 15 header bytes, then 300 rows of 400 pixels, three bytes each, top row first
- Acceptance by both readers we tried, each showing the same pixels as our PNG of the HEIC
Lost or not yet supported
- Compression: 360,015 bytes, 16 times the HEIC.
- EXIF and XMP, including the sample's GPS tags.
- Transparency. The file has no alpha channel; a HEIC with one is blended onto
AlphaColor. - Correct tones for Display P3-tagged HEIC files, which the decoder stretches.
Limits
- One HEIC per request, at most 100,000,000 pixels.
- Requests up to 10 MB on the Free plan or 100 MB on paid plans; 120 seconds per conversion.
- Values are 8 bits per channel: the header's maximum value is 255.
Where teams use it
Feeding image-processing code
Research code and command-line tools that read portable anymaps need no image decoder. Converting HEIC here keeps HEVC decoding out of that code.
Comparing decoders byte for byte
With a 15-byte header and raw rows, two PNM files from different decoders can be compared directly, pixel by pixel.
Questions
Which PNM variant is it?
Binary PPM. The file starts P6, a newline, then 400 300 255 (width, height and maximum value) and another newline; red, green and blue bytes follow for each pixel. With ColorSpace=gray or monochrome it is a P5 graymap with one byte a pixel.
How do I read it without a library?
Read the magic number and the three numbers after it, skip the single whitespace byte that ends the header, then read width × height × 3 bytes: red, green and blue for each pixel, row by row from the top.
Does the PNM keep the photo's metadata?
No. The header has room for comments, but none are written, and the sample's EXIF block with camera name and GPS position is dropped.
Convert your first HEIC file in a minute.