Parsing Images
Extract structured content from PNG and JPEG images.
Bitparse accepts PNG and JPEG images in addition to PDFs. Each image is treated as a single page.
How It Works
- Upload a PNG or JPEG via
POST /parse. - The image is analyzed for text, tables, equations, figures, and charts.
- The response contains a single entry in the
pagesarray withpage_number: 1.
File type is detected by magic bytes, not file extension. A .png file that is actually a JPEG will be processed as a JPEG.
Credit Cost
Each image costs 1 credit (one page).
Supported Formats
| Format | MIME Type | Magic Bytes |
|---|---|---|
| PNG | image/png | 89 50 4E 47 |
| JPEG | image/jpeg | FF D8 FF |
Other image formats (WebP, TIFF, BMP, GIF) are not supported and will return 400 Bad Request.
Examples
Parsing a PNG
curl -X POST https://api.bitparse.ai/parse \
-H "X-API-Key: bp_YOUR_API_KEY" \
-F "file=@whiteboard-photo.png"import requests
resp = requests.post(
"https://api.bitparse.ai/parse",
headers={"X-API-Key": "bp_YOUR_API_KEY"},
files={"file": open("whiteboard-photo.png", "rb")},
)
data = resp.json()
print(data["pages"][0]["text"])Parsing a JPEG
curl -X POST https://api.bitparse.ai/parse \
-H "X-API-Key: bp_YOUR_API_KEY" \
-F "file=@scan.jpg"import requests
resp = requests.post(
"https://api.bitparse.ai/parse",
headers={"X-API-Key": "bp_YOUR_API_KEY"},
files={"file": ("scan.jpg", open("scan.jpg", "rb"), "image/jpeg")},
)
data = resp.json()
for elem in data["pages"][0]["elements"]:
print(f"[{elem['type']}] {elem['content'][:80]}")Example Response with Figure Extraction
When the image contains embedded figures or diagrams, Bitparse extracts them as base64-encoded PNGs:
{
"pages": [
{
"page_number": 1,
"text": "<title id=\"page1_elem0\">System Architecture</title>\n\n<text id=\"page1_elem1\">The diagram below shows the data pipeline from ingestion to output.</text>\n\n<figure id=\"page1_elem2\"/>",
"elements": [
{"id": "page1_elem0", "type": "title", "content": "System Architecture", "image_data": ""},
{"id": "page1_elem1", "type": "text", "content": "The diagram below shows the data pipeline from ingestion to output.", "image_data": ""},
{"id": "page1_elem2", "type": "figure", "content": "", "image_data": "iVBORw0KGgoAAAANSUhEUgAA..."}
]
}
],
"total_pages": 1,
"processing_time_ms": 1102,
"credits_used": 1,
"credits_remaining": 498
}Working with Base64 Image Data
Elements of type figure, image, or chart include base64-encoded PNG data in the image_data field. To save the extracted image to disk:
import base64
elements = data["pages"][0]["elements"]
for elem in elements:
if elem["image_data"]:
img_bytes = base64.b64decode(elem["image_data"])
with open(f"{elem['id']}.png", "wb") as f:
f.write(img_bytes)
print(f"Saved {elem['id']}.png")Tips
- Resolution matters: Higher-resolution images produce better extraction results, especially for tables and equations.
- Crop before uploading: If you only need a portion of the image, cropping it first reduces processing time and improves accuracy.
- One page per image: Unlike PDFs, every image is always 1 page and costs 1 credit.