# Compress image to a file size

Compress an image to fit under a target file size in KB, such as 100 KB or 2 MB, for upload limits and forms.

- Endpoint: `POST https://setget.net/v1/tools/image-compress-to-size` with JSON `{"input": {...}}` (add `"wait": 30` to hold the reply until the job finishes)
- MCP: `run_tool` with `slug` = `image-compress-to-size`
- Page: https://setget.net/tools/image-compress-to-size

## Files in, files out

This is a file tool. Its file inputs take file references, not file contents and not web addresses.

- Get a reference by uploading: `curl -T FILE https://setget.net/drop/` prints a line `ref  <id>/f1`. Or `POST https://setget.net/v1/drops` with `{"files":[{"name","size"}]}`, PUT the bytes to the returned `upload.url` with the listed headers, and use the file's `ref`. Over MCP use the `drop` tool. A file under about 700 KB can also be sent in place as a `data:<type>;base64,<content>` URI.
- Uploads are at most 100 MB per file, are readable by anyone with the link, and expire (one hour by default). Programs are refused.
- The tool runs as a job. The reply is `{"tool", "ms", "result", "files", "job"}`: `result` is JSON, and every result file comes back in `files` as `{"name", "size", "content_type", "kind", "url", "ref"}`. Download it from `url`, or pass `ref` as the input of another file tool.
- A job still running when the wait ends answers 202 with `job`. Follow it with `GET https://setget.net/v1/jobs/<id>?wait=30`, or stream progress from `GET https://setget.net/v1/jobs/<id>/events` (over MCP: the `job` tool). A person can watch it at `job.url`.

## Inputs

- `image` (required, file, a file reference such as `DROP_ID/f1`, accepts image): The image to compress.
- `target_kb` (required, number, range 0.1..50000): Largest allowed file size in kilobytes. 1 MB is 1000 KB.
- `format` (optional, string, one of `jpg`, `webp`, `avif`): Format of the result. Leave empty to keep JPG, WebP or AVIF; other images become JPG, or WebP when they have transparency.

## Example 1: Fit a photo under 10 KB

Upload first. Each placeholder below stands for the reference of one upload: `DROP_ID/f1` = [sample.jpg](https://setget.net/static/samples/sample.jpg).

```json
{"input":{"image":"DROP_ID/f1","target_kb":10},"wait":30}
```

## Example 2: Under 4 KB as WebP

Upload first. Each placeholder below stands for the reference of one upload: `DROP_ID/f1` = [sample.png](https://setget.net/static/samples/sample.png).

```json
{"input":{"image":"DROP_ID/f1","target_kb":4,"format":"webp"},"wait":30}
```

**How does it reach the size?** It looks for the highest quality that fits. If even a low quality is too big, it makes the image smaller in pixels and tries again. The result reports the quality and scale used.

**Is the result always under the target?** Yes. A kilobyte is counted as 1000 bytes, so the file also passes limits that count 1024 bytes per KB. If the target cannot be reached you get an error instead of an oversized file.

**What happens to transparency?** WebP and AVIF keep it. JPG cannot, so transparent areas turn white.
