Image Resize & Convert API
Resize, crop, rotate, flip and convert images between PNG and JPEG with high-quality resampling and adjustable JPEG quality to shrink file size.
The image resize API transforms an uploaded PNG or JPEG. Set width and / or height (the other side keeps the aspect ratio) and a fit: inside (default, fits in the box), cover (fills the box and crops the centre, ideal for thumbnails), contain (fits and pads with a background colour) or fill (stretches). crop=x,y,width,height cuts a region first, rotate (90, 180, 270) and flip (horizontal, vertical) fix orientation, and no_enlarge=true never upscales.
Shrinking uses area averaging, which keeps fine details sharp without aliasing; enlarging uses bilinear interpolation. Output format=jpeg with quality (1–100, default 82) to reduce size; transparent areas are flattened on the background colour. Headers report the new size and the input / output byte counts.
Images up to 25 megapixels and the file size of your plan are accepted; everything runs in memory and nothing is stored.
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
file | body | file | yes | PNG or JPEG (multipart, raw body or file_base64). | |
width | query|body | number | no | Target width (px). | |
height | query|body | number | no | Target height (px). | |
fit | query|body | string | no | inside | inside, cover, contain, fill. |
crop | query|body | string | no | x,y,width,height before resizing. | |
rotate | query|body | number | no | 90, 180 or 270. | |
flip | query|body | string | no | horizontal or vertical. | |
format | query|body | string | no | png or jpeg (default: same as input). | |
quality | query|body | number | no | 82 | JPEG quality 1–100. |
background | query|body | string | no | ffffff | Padding / flatten colour. |
Example
curl -X POST "https://apibox.io.vn/v1/image-resize?width=400&height=400&fit=cover&format=jpeg" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "0=@./my-file" \
-o outputconst form = new FormData();
form.append('0', fileInput.files[0]);
const res = await fetch('https://apibox.io.vn/v1/image-resize?width=400&height=400&fit=cover&format=jpeg', {
method: 'POST',
headers: { Authorization: 'Bearer YOUR_API_KEY' },
body: form,
});
console.log(await res.json());import requests
res = requests.post(
"https://apibox.io.vn/v1/image-resize?width=400&height=400&fit=cover&format=jpeg",
headers={"Authorization": "Bearer YOUR_API_KEY"},
files={"0": open("my-file", "rb")},
timeout=30,
)
open("output", "wb").write(res.content)<?php
$ch = curl_init('https://apibox.io.vn/v1/image-resize?width=400&height=400&fit=cover&format=jpeg');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY'],
CURLOPT_POSTFIELDS => ['0' => new CURLFile('my-file')],
]);
$response = curl_exec($ch);
file_put_contents('output', $response);Response
binary image/jpeg
Use cases
- Thumbnails and avatars from user uploads
- Shrink photos before storing them
- Convert PNG screenshots to lighter JPEG
- Square images for marketplaces and social networks
FAQ
Is EXIF orientation applied?
Not automatically; use rotate= when a photo appears sideways (image-metadata tells you the EXIF orientation).
Is WebP supported?
Not yet: PNG and JPEG in and out.
What is the size limit?
25 megapixels and the file size of your plan (5–50 MB).
Related APIs
QR Code Generator
Generate QR codes as PNG or SVG with one GET request: URLs, text, WiFi logins, vCards, e-mail, SMS, phone and geo links. Custom colours, size and ECC.
|||Barcode Generator
Create Code 128 barcodes for labels, SKUs and shipping with a single request. SVG with human-readable text or PNG, custom height, width and colours.
▭Placeholder Image
Get placeholder images of any size for mockups and tests: /v1/placeholder/600x400.png. SVG with custom text and colours, or a solid-colour PNG.