Sada Files

Developer docs

  1. Developers
  2. Tool endpoints

Compress Image to Exact Size API

Hit a hard limit — under 20 KB, 50 KB, 100 KB, 200 KB, 1 MB — by reducing quality first, then dimensions.

Environment

EnvironmentBase URL
Productionhttps://api.sadafiles.com/v1

There is one environment and no sandbox, so every request here is real and counts toward your limits.

Request

POSThttps://api.sadafiles.com/v1/tools/compress-to-size
Content type
multipart/form-data
Auth
X-API-Key with tools:run
Accepts
jpg, png, webp, avif, gif, bmp, tiff, heic and 1 more
Files per request
1 to 500
Largest file
2 GB
Job timeout
120 s
Rate weight
2 units

Parameters

Send these as a JSON string in the options form field. Anything else is rejected.

NameTypeDefaultAllowed
targetKbinteger100min 5, KB
minWidthinteger200min 16, px
formatstringsamesame, jpg, webp, png
widthinteger—min 1, max 30000, px
heightinteger—min 1, max 30000, px
fitstringinsideinside, cover, fill, contain
keepAspectbooleantrue—
preserveDimensionsSearch quality only. Providing width or height always locks the resulting dimensions. An impossible size limit reports an error.booleanfalse—

Response

StatusBodyWhen
201sameThe run finished within 60 seconds
202Job summary JSONStill running; poll the job
4xx, 5xxError JSONSee error codes

A file response carries X-Sada-Job and X-Sada-Expires-At. For long work, post to /v1/tools/compress-to-size/jobs instead. See jobs and webhooks.

Also runs on the device

In the web tool and apps, Compress Image to Exact Size can run locally with no upload. The API always processes on the server.

Ready settings

These settings power the matching pages on the site, and work the same in the API.

Useoptions
Compress Image to 20 KB{"targetKb":20,"format":"jpg"}
Compress Image to 50 KB{"targetKb":50,"format":"jpg"}
Compress Image to 100 KB{"targetKb":100,"format":"jpg"}
Compress Image to 200 KB{"targetKb":200,"format":"jpg"}
Compress Signature Image to 20 KB{"targetKb":20,"format":"jpg"}
Compress Photo to 50 KB for SSC / UPSC Forms{"targetKb":50,"format":"jpg"}
Compress JPG to 10 KB{"format":"jpg","targetKb":10,"minWidth":16}
Compress JPG to 20 KB{"format":"jpg","targetKb":20,"minWidth":16}
Compress JPG to 50 KB{"format":"jpg","targetKb":50,"minWidth":16}
Compress JPG to 100 KB{"format":"jpg","targetKb":100,"minWidth":16}
Compress JPG to 200 KB{"format":"jpg","targetKb":200,"minWidth":16}
Compress JPG to 300 KB{"format":"jpg","targetKb":300,"minWidth":16}

Try it yourself!

Pick a file, set the options and run a real request with your key. The code follows your changes.

Headers

You need a free key to run this request. Sign in and create a key.

Body

curl -X POST "https://api.sadafiles.com/v1/tools/compress-to-size" \  -H "X-API-Key: $SADAFILES_API_KEY" \  -F "files[]=@input.jpg" \  -o output.same

What's next?