PNM to TGA API
POST a netpbm image to /v2/convert/pnm/to/tga and get an uncompressed 32-bit Targa file. The 230,415-byte sample PPM came back as 307,218 bytes, an 18-byte header and 4 bytes per pixel: the same RGB values plus an alpha channel set to 255.
- Endpoint
- POST /v2/
convert/ pnm/ to/ tga - Accepts
- pnm
- Sample timing
- under 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/pnm/to/tga \
-H "Authorization: Bearer $PDFCONVERSIONAPI_KEY" \
-F File=@three-spheres-render.ppm \
-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/pnm/to/tga",
headers={"Authorization": f"Bearer {key}"},
files=[("File", open("three-spheres-render.ppm", "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 = "three-spheres-render.ppm";
form.append("File", new Blob([await readFile(file)]), file);
const url = "https://api.pdfconversionapi.com/v2/convert/pnm/to/tga";
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,
"Files": [
{
"FileName": "three-spheres-render.tga",
"FileExt": "tga",
"FileSize": 307218,
"FileData": "AAACAAAAAAAAAAAAQAHwACAo…"
}
]
}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
- three-spheres-render.ppm (225 KB)
- Output
- three-spheres-render.tga (300 KB)
- Source
- A 320 x 240 frame from a small ray tracer we wrote for this page (three spheres on a checkered floor), saved as a binary PPM (P6) with 8 bits per channel. (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 | Width of the TGA; 128 px wide the render is 128 × 96 and 49,170 bytes.Values: 1–20000 |
ImageHeightinteger | Height of the TGA, or with a width the fitting box.Values: 1–20000 |
ScaleProportionsboolean, default true | false stretches the frame to an exact width and height, for texture slots of a fixed shape. |
ScaleIfLargerboolean, default false | true turns the resize into a downscale only. |
ScaleImageboolean, default true | false crops a top-left area instead of scaling. |
ColorSpaceenum, default default | gray and monochrome change the values only: red, green and blue become equal, and both files stay 32-bit at 307,218 bytes, like the default.Values: default, rgb, gray, monochrome |
TransparentColorstring | Gives alpha 0 to one exact color: #92969D clears 19,013 pixels, the flat gray of the dark floor tiles where no shadow falls; shadowed and distant tile pixels keep alpha 255.Values: Color name, #RRGGBB or R,G,B |
ImageResolutioninteger | Accepted but not written to the TGA.Values: 10–800 |
ImageInterpolationboolean, default false | Accepted; scaling uses Lanczos. |
FileNamestring | Name of the .tga; the upload's by default. |
StoreFileboolean, default false | Return a 3-hour link instead of base64. |
What carries over, and what doesn't
Kept
- Every pixel: decoding the sample TGA gives the PPM's RGB values exactly
- Alpha from PAM input: a test file's alpha values of 0, 128 and 255 came through
- Top-down row order, marked in the header
- An uncompressed type 2 file, which the three readers we tested all opened as it is
Lost or not yet supported
- Size. Without compression and with an added alpha byte, the TGA is a third larger than the PPM: 307,218 against 230,415 bytes.
- Gray storage: a PGM becomes a 32-bit color TGA with equal red, green and blue.
- 16-bit depth, reduced to 8 bits.
Limits
- One file per request.
- Requests up to 10 MB on the Free plan or 100 MB on paid plans, all files and fields together.
- Images over 100,000,000 pixels return 413.
- Each side can be at most 65,535 px: a 65,536 × 2 PPM returned 413 "TGA images can be at most 65,535 pixels on a side, and this one is 65,536×2", while the 65,535 × 2 one converted.
- 120 seconds per conversion, then 504.
Where teams use it
Frame sequences for video and game tools
Render code that writes PPM frames can produce numbered TGA frames instead, one request per frame, for tools that import Targa sequences.
Textures with an alpha channel from PAM
A P7 RGB_ALPHA file keeps its alpha in the TGA, so masks and cut-outs generated by netpbm-based code arrive with their transparency.
Questions
Will older Targa readers open the file?
It uses the simplest true-color layout: image type 2, no color map, 32 bits per pixel and the top-left origin flag set in the header. The three readers we tested opened the sample without changes. There is no TGA 2.0 footer.
Is the TGA compressed?
No. There is no run-length encoding and no option to turn it on, so every result takes 4 bytes per pixel plus an 18-byte header. Flat images gain nothing: the monochrome render is the same 307,218 bytes as the full-color one.
What happens to a grayscale PGM?
It is written as a 32-bit color TGA in which red, green and blue are equal and alpha is 255.
Convert your first PNM file in a minute.