Image resize API

Resize inside a box, keeping proportions. Put 800x600, 800x, x600 or 50% in "option".

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

When to call it

Nothing should serve a four-thousand-pixel photograph to a phone. Resizing on upload, in the job that receives the file, is what fixes page weight for every image rather than for the ones somebody remembered to export properly.

For a one-off, the browser version needs no token and never sends your data anywhere: it runs on your own machine.

Example

curl
curl -X POST https://astralbatch.com/api/v1/image-resize \
  -H "Authorization: Bearer ast_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"input": "iVBORw0KGgoAAAANSUhEUg...", "option": "800x600"}'
response
{
  "tool": "image-resize",
  "result": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgK...",
  "chars": 74210,
  "ms": 96
}

In your language

JavaScript
const res = await fetch("https://astralbatch.com/api/v1/image-resize", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.ASTRAL_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"input": "iVBORw0KGgoAAAANSUhEUg...", "option": "800x600"}),
});
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-resize",
    headers={"Authorization": f"Bearer {os.environ['ASTRAL_TOKEN']}"},
    json={"input": "iVBORw0KGgoAAAANSUhEUg...", "option": "800x600"},
    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.
optionstringSee the example above.

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

How do I keep the proportions?
They are always kept. "800x600" fits the image inside that box, so a 400 by 200 image asked for 100 by 100 comes back 100 by 50 rather than squashed to a square.
Can I set only the width?
Yes. "800x" sets the width and lets the height follow, "x600" does the reverse, and "50%" scales against the source width.
Will it enlarge a small image?
Yes, if you ask for a larger size. Enlarging cannot add detail, so the result is softer than the original; there is no upscaling model behind this.

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