Convert API
Synchronous conversion: POST /convert waits and returns the file or a ZIP.
From 1.1.0-rc.6. https://imgcompress.example.com stands for your instance.
Synchronous conversion: POST /convert waits and returns the file or a ZIP.
From 1.1.0-rc.6. https://imgcompress.example.com stands for your instance.
Convert and get the result right away
Needs the API key when PUBLIC_API_KEY is set. Operation ID: convert.
When: Use for one image or a small batch when you can wait for the answer. Nothing to call before.
Compress, convert, resize, remove the background, upscale or fit images, and get the result in the answer. One result comes back as the file itself, several as a ZIP (output=zip always gives a ZIP). Nothing is kept on the container afterwards.
The request stays open until the conversion is done. For AI upscaling or big batches, use POST /jobs: proxies often cut long requests.
Response headers: X-Converted-Count and X-Failed-Count. Files that fail in a batch are left out of the ZIP; when all fail, the answer is 422.
bash# Compress a photo to WebP, 1600 px wide curl -fsS https://imgcompress.example.com/api/v1/convert \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ -F "files[]=@photo.jpg" -F format=webp -F quality=80 -F width=1600 \ -o photo.webp
bash# Remove the background, keep transparency curl -fsS https://imgcompress.example.com/api/v1/convert \ -H "Authorization: Bearer $PUBLIC_API_KEY" \ -F "files[]=@product.jpg" -F format=png -F remove_background=true -o product.png
multipart/form-data, required.
| Field | Type | Required | Description |
|---|---|---|---|
files[] | array of file | yes | The images to convert; repeat the field for a batch. 'file' works as well, for a single upload. |
format | string | yes | Output format (case-insensitive). Values: jpeg, png, ico, avif, webp, pdf. Recommended: webp. Required. |
quality | integer | no | Compression quality for lossy formats (JPEG, WebP, AVIF). Range: 1 to 100. Recommended: 80. If omitted: 85. |
width | integer | no | Resize to this width in pixels, keeping the aspect ratio. Ignored with upscale or fit to size. Min: 1. If omitted: not applied. |
target_size_kb | integer | no | Largest output file size in KiB. Quality is lowered until the file fits. Not with webp_lossless. Min: 1. If omitted: not applied. |
remove_background | boolean | no | Remove the background with the bundled AI model (offline). Use png, webp or avif to keep transparency. If omitted: off. Alias: use_rembg. |
webp_lossless | boolean | no | Lossless WebP (format webp only). If omitted: off. |
upscale | string | no | AI upscaling (Real-ESRGAN, offline). A factor or a target resolution. Not for PDF output. Slow on big images: prefer POST /jobs. Values: 2x, 4x, 8x, 1080p, 4k, 6k, 8k, 16k. If omitted: not applied. |
upscale_model | string | no | Upscaling model: photos (general), less denoising, or anime/drawings. Values: general, general-denoise-medium, general-denoise-low, anime. If omitted: general. |
fit_width | integer | no | Fit to size: output width in pixels. Needs fit_height. Range: 1 to 8192. Recommended: 1080. If omitted: not applied. |
fit_height | integer | no | Fit to size: output height in pixels. Needs fit_width. Range: 1 to 8192. Recommended: 1080. If omitted: not applied. |
fit_mode | string | no | Fit to size: crop to fill, or fit inside on a blurred, solid or transparent background. Values: crop, blur, solid, transparent. If omitted: crop. |
fit_anchor | string | no | Fit to size, mode crop: which part to keep. auto finds the subject. Values: auto, center, top, bottom, left, right. If omitted: auto. |
fit_color | string | no | Background colour for fit mode solid, as hex. If omitted: not applied. |
fit_scale | number | no | Image size on the canvas; 1 is the largest size that still fits. Range: 0.01 to 20. If omitted: not applied. |
fit_x | number | no | Image centre as a share of the canvas width (0.5 = centred). Needs fit_y. Range: -1 to 2. If omitted: not applied. |
fit_y | number | no | Image centre as a share of the canvas height (0.5 = centred). Needs fit_x. Range: -1 to 2. If omitted: not applied. |
pdf_preset | string | no | PDF output: page size. original keeps each image's own size. Values: original, a4-auto, a4-portrait, a4-landscape, letter-auto, letter-portrait, letter-landscape, mobile-portrait, mobile-landscape. If omitted: original. |
pdf_scale | string | no | PDF output: fit the image on the page, or fill the page. Values: fill, fit. If omitted: fit. |
pdf_margin_mm | number | no | PDF output: page margin in millimetres. Range: 0 to 30. If omitted: 10. |
pdf_paginate | boolean | no | PDF output: split tall images over several pages. If omitted: off. |
pdf_quality | string | no | PDF output: image resolution and compression. Values: small, medium, high, ultra. If omitted: high. |
relative_dirs[] | array of string | no | Folder of each file, in upload order (e.g. holiday/day1), to keep the folder structure in the ZIP. Give one per file or none. If omitted: not applied. |
output | string | no | POST /convert only: auto answers with the file itself for one result and a ZIP for several; zip always answers with a ZIP. Values: auto, zip. If omitted: auto. |
| Status | Meaning | Content |
|---|---|---|
| 200 | The converted file, or a ZIP of all results. Content-Disposition has the file name. | image/jpeg, image/png, image/webp, image/avif, image/vnd.microsoft.icon, application/pdf, application/zip. Headers: X-Converted-Count, X-Failed-Count |
| 400 | Invalid options or form. message says which field and what is allowed. | application/json |
| 401 | PUBLIC_API_KEY is set and the request is neither from the web UI nor carries the key. | application/json |
| 403 | A browser on another website sent this while ENABLE_PUBLIC_API is off, or the feature is turned off on this container (storage management). | application/json |
| 413 | The request is larger than MAX_UPLOAD_SIZE_MB. Nothing was stored. | application/json |
| 415 | A file type the container cannot read. GET /formats lists supported_formats. | application/json |
| 422 | The files were readable as a form but none could be converted. | application/json |
| 500 | Unexpected failure inside the container; details are in the container log. | application/json |