Resize image to target file size
Resize image to target file size estimates the compression quality and proportional scale needed to fit a stated size limit.
Run — free
Enter the source width and height, choose JPEG, PNG, WebP, or AVIF, and provide the maximum size in decimal kilobytes. The calculator returns suggested dimensions, quality, estimated size, and the smallest realistic estimate. It works from metadata rather than image pixels, so its result is a planning estimate, not a promise about a particular encoder or photograph. The same inputs always produce the same answer.
Turn a file-size limit into practical export settings
Start with the image's actual pixel width and height, its intended output format, and the maximum file size accepted by the destination. The calculator first estimates a normal export at a format-specific reference quality. If that estimate already fits, it preserves the original dimensions and recommends no change. For lossy JPEG, WebP, and AVIF output, it next lowers the modeled quality while keeping every pixel. When quality alone is unlikely to be enough, it holds a conservative minimum quality and calculates a proportional scale for both dimensions. PNG is treated as lossless, so it recommends scaling rather than pretending that a JPEG-style quality slider controls its size. The output includes the chosen action, integer output dimensions, scale percentage, quality, estimated file size, original estimate, and minimum estimate. Use these values as the first settings in an image encoder, then measure the encoded result and make a small final adjustment if the receiving service enforces a strict byte limit.
Understand what the estimate can and cannot know
File size cannot be derived exactly from dimensions and format alone. A flat icon, a noisy night photograph, and a detailed illustration can share the same width, height, and format yet compress to very different sizes. Encoder implementations, chroma subsampling, metadata, animation, alpha transparency, color profiles, and optimization settings add more variation. This calculator therefore uses a transparent analytic model: each supported format has a typical number of compressed bytes per pixel, a small container overhead, a reference quality, and, for lossy formats, a smooth quality curve. The returned confidence is deliberately labeled as a rough estimate. It does not inspect, upload, decode, or alter the image, and it never claims to produce an exact file. For reliable production automation, encode once with the recommendation, compare the resulting bytes with the target, and use an encoder's bounded search to converge. The estimate is most valuable before encoding, when you need a sensible initial quality and resolution instead of guessing blindly or repeatedly trying unrelated settings.
Handle very small targets without unusable recommendations
An arbitrarily tiny target is not realistic for every image. Even an empty image file needs headers and container data, and shrinking a large photograph to a nearly invisible bitmap is rarely a useful interpretation of resize. The calculator establishes a practical floor by preserving the source aspect ratio while allowing the shorter side to fall no lower than 32 pixels, then applying the format's minimum modeled quality. If the requested target is below that estimate, the request fails with an invalid-input error that states the calculated minimum in kilobytes. This is preferable to returning zero-sized dimensions, negative arithmetic, or an apparent guarantee that no ordinary encoder could meet. Decimal kilobytes are used, meaning one KB is modeled as 1,000 bytes. Dimensions must be positive integers, the total source area is bounded, and output dimensions are rounded down to whole pixels so the estimate stays at or below the modeled target. Always preserve a safety margin when an upload portal rejects files at an exact boundary.
What you can do with it
Prepare an upload for a strict portal
Estimate a usable quality and resolution before exporting an image for a form with a fixed KB limit.
Choose responsive image budgets
Translate a performance budget into approximate dimensions and compression settings for generated variants.
Seed an encoder search
Give an automated compression loop a sensible starting quality and scale, reducing unnecessary trial encodes.
FAQ
Will the encoded file have exactly the estimated size?
No. Pixel content and encoder settings affect compression, so the result is a rough planning estimate. Encode and measure the actual file for strict limits.
Why does PNG always return quality 100?
PNG is modeled as lossless. Its compression level affects processing effort more than visual quality, so scaling is the meaningful recommendation.
What happens when the target is too small?
The request returns an invalid-input error with the realistic minimum estimated for the dimensions and format.
Does the calculator upload or inspect my image?
No. It receives dimensions, format, and target size only; it never receives or processes image pixels.
How much does an API request cost?
Each API request costs $0.002.
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/image/resize-to-filesize \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"width":4000,"height":3000,"format":"jpeg","target_kb":500}'const res = await fetch("https://api.kit.forhosting.com/image/resize-to-filesize", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"width": 4000,
"height": 3000,
"format": "jpeg",
"target_kb": 500
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/image/resize-to-filesize",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"width": 4000,
"height": 3000,
"format": "jpeg",
"target_kb": 500
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/image/resize-to-filesize", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"width":4000,"height":3000,"format":"jpeg","target_kb":500}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"width":4000,"height":3000,"format":"jpeg","target_kb":500}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/image/resize-to-filesize", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"width": 4000,
"height": 3000,
"format": "jpeg",
"target_kb": 500
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "image.resize_to_filesize",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_mb | 15 |
max_megapixels | 12 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |