Image metadata API

Format, dimensions, transparency, orientation and byte size.

EndpointPOST https://astralbatch.com/api/v1/image-info
AuthBearer token, free
Sendsinput: base64
Returnsresult: json
PriceFree. 1,000 calls a day, 60 a minute.

When to call it

Validation comes before processing: is this really a JPEG, is it portrait, is it eight thousand pixels wide, does it have an alpha channel that will turn black when flattened. Answering that on upload is what stops a bad file reaching the step that assumed a good one.

Example

curl
curl -X POST https://astralbatch.com/api/v1/image-info \
  -H "Authorization: Bearer ast_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"input": "iVBORw0KGgoAAAANSUhEUg..."}'
response
{
  "tool": "image-info",
  "result": "{\n  \"format\": \"jpeg\",\n  \"width\": 4032,\n  \"height\": 3024,\n  \"bytes\": 2841902,\n  \"hasAlpha\": false,\n  \"orientation\": 6,\n  \"density\": 72\n}",
  "chars": 148,
  "ms": 9
}

In your language

JavaScript
const res = await fetch("https://astralbatch.com/api/v1/image-info", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"input": "iVBORw0KGgoAAAANSUhEUg..."}),
});
if (!res.ok) throw new Error((await res.json()).detail);
const { result } = await res.json();
Python
import os, requests

res = requests.post(
    "https://astralbatch.com/api/v1/image-info",
    headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
    json={"input": "iVBORw0KGgoAAAANSUhEUg..."},
    timeout=30,
)
res.raise_for_status()
result = res.json()["result"]

Parameters

FieldTypeNotes
inputstringRequired. The file, base64 encoded. A data: URL is accepted too. Up to 10,000,000 characters per call.

Errors

Errors are RFC 7807 problem documents with a stable type you can branch on.

missing-token401No Authorization header.
bad-request400input missing or the wrong type.
tool-failed422The input could not be processed. detail says why.
quota-exceeded429Past 1,000 calls today.

Questions

Does it download the whole image?
You send it, base64 in the request body. It is read in memory and not written to disk, and only the call itself is recorded.
What is the orientation field?
The EXIF orientation tag, 1 to 8. A value of 6 means the camera was rotated and the pixels are stored sideways, which is why a photo can look right on a phone and wrong everywhere else.
Which formats can it read?
JPEG, PNG, WebP, AVIF, TIFF, GIF and SVG. Anything it cannot read is refused with a message rather than guessed at.

Other endpoints

A token takes thirty seconds

Free, no card, 1,000 calls a day, and the same token works on astraltext.com, astralpdf.com, astraljson.com and astralbatch.com.

Get a free token