Image resize
POST https://tools.yukai.uk/api/v1/image/resize
Resize an image. Resizes to width and/or height. fit: contain (default; fits inside the box, keeps the aspect ratio, may enlarge), scale-down (like contain, never enlarges), cover (fills the box and crops; gravity=auto keeps the most interesting part), crop (like cover, never enlarges), pad (fits inside and fills the rest with background, transparent by default; white for JPEG), squeeze (stretches to the exact size). The format stays the same unless format is set (GIF becomes PNG). Typical time under 1 second. Send an image URL (GET or POST), a base64 image (POST JSON), a file upload (POST multipart/form-data, field image) or the raw image bytes (POST with Content-Type: image/*, options in the query string). The answer is the image itself by default (response=json for metadata + base64). One call = one image. The same image with the same options is answered from a 24-hour cache.
Cost
Credits: 18 ($0.0018) per successful call. Failed calls are free. Source price: ai-image-toolkit/image-processed.
Input
Send a JSON body (POST) or the same fields as a query string (GET).
No field is required.
| Field | Type | Default | Description |
|---|---|---|---|
url | string | Public image URL (JPEG, PNG, WebP or GIF, up to 10 MB, 50 megapixels and 12,000 px per side). Private, local and cloud-metadata addresses are refused on every redirect. Alias: imageUrl. For POST you can send image (base64) or upload the file instead. | |
width | integer | Target width in pixels. At least one of width/height. | |
height | integer | Target height in pixels. | |
fit | string | "contain" | How the image fits the box (see the description). |
gravity | string | "center" | With fit=cover/crop: which part to keep. auto picks the most interesting area. |
format | string | "auto" | auto keeps the input format (GIF becomes PNG). |
quality | integer | 85 | Quality for JPEG, WebP and AVIF (ignored for PNG, which is lossless). Default 85. |
background | string | With fit=pad, or for transparent areas in a JPEG: fill color (ffffff, white, rgb(...)). | |
response | string | "image" | image (default): the response body is the image itself (Content-Type: image/..., metadata in x-* headers). json: JSON with the metadata and the image as base64 in image (results up to 15 MB). |
image | string | The image itself as base64 or a data URL (data:image/png;base64,...), up to 10 MB decoded. POST only. Aliases: imageBase64, base64. |
Examples
Replace tt_live_XXXX with your key from the pricing page.
curl
curl -i -X POST "https://tools.yukai.uk/api/v1/image/resize" \
-H "Authorization: Bearer tt_live_XXXX" \
-H "Content-Type: application/json" \
-d '{"url":"https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/960px-Cat03.jpg","width":400,"height":400,"fit":"cover","gravity":"auto","response":"json"}'JavaScript (fetch)
const res = await fetch("https://tools.yukai.uk/api/v1/image/resize", {
method: "POST",
headers: { "Authorization": "Bearer tt_live_XXXX", "Content-Type": "application/json" },
body: JSON.stringify({"url":"https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/960px-Cat03.jpg","width":400,"height":400,"fit":"cover","gravity":"auto","response":"json"}),
});
console.log(res.status, res.headers.get("x-credits-charged"), res.headers.get("x-credits-balance"));
console.log(await res.json());Python (requests)
import requests
r = requests.post(
"https://tools.yukai.uk/api/v1/image/resize",
headers={"Authorization": "Bearer tt_live_XXXX"},
json={"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/960px-Cat03.jpg", "width": 400, "height": 400, "fit": "cover", "gravity": "auto", "response": "json"},
timeout=120,
)
print(r.status_code, r.headers.get("x-credits-charged"), r.headers.get("x-credits-balance"))
print(r.json())
Response
JSON with "success": true and the result fields; on failure {"success": false, "error": {"code", "message", "retryable"}} and no credits are used. Every answer carries x-credits-charged (credits used) and x-credits-balance (balance after the call); check the balance any time with GET https://tools.yukai.uk/v1/billing/balance.
Full field list and response schema: OpenAPI spec image-tools (its servers entry is the marketplace gateway; call https://tools.yukai.uk with your key).