Get any photo down to 20KB in seconds
Drop your image in, set 20KB as your target, and download a compressed file that fits strict upload limits - no account, no software, no waiting. Everything runs inside your browser, so your image is never sent to any server.
A 20KB ceiling is a real-world constraint you'll hit on government forms, job portals, school admissions sites, and profile photo uploads. This tool hits that target by automatically adjusting JPEG quality until the file size falls at or below 20KB.
How to compress an image to 20KB
- Upload your image - drag it onto the tool or click "Choose File." JPEG, PNG, and WebP are all accepted.
- Set the target size - the tool defaults to 20KB. Change it if you need a different limit.
- Click Compress - the browser crunches the image using a canvas and adjusts quality automatically.
- Download the result - hit "Download" and you get a compressed JPEG, ready to upload anywhere.
The whole process typically takes under two seconds, even on a phone.
Worked example: a 2.4 MB passport photo → under 20KB
Say you have a 2400 × 2400 px passport photo at 2.4 MB (JPEG). Most government portals cap photo uploads at 20KB or 50KB.
| Property | Before | After |
|---|---|---|
| File size | 2,400 KB | ~19 KB |
| Format | JPEG | JPEG |
| Dimensions | 2400 × 2400 px | 2400 × 2400 px |
| JPEG quality | ~95 | ~22 (auto-set) |
The pixel dimensions stay the same. Only the quality level drops, which reduces the data stored per pixel. At 20KB the image still looks recognisable for form purposes, though fine detail will be softer than the original.
How to compress an image to 20KB in code
If you need to automate this in a script or app, here are two quick ways.
Python (Pillow)
# pip install Pillow
from PIL import Image
import io
def compress_to_target(input_path, output_path, target_kb=20):
target_bytes = target_kb * 1024
img = Image.open(input_path).convert('RGB')
quality = 85
while quality > 5:
buf = io.BytesIO()
img.save(buf, format='JPEG', quality=quality)
if buf.tell() <= target_bytes:
break
quality -= 5
with open(output_path, 'wb') as f:
f.write(buf.getvalue())
print(f'Saved {buf.tell() / 1024:.1f} KB at quality {quality}')
compress_to_target('photo.jpg', 'photo_20kb.jpg', target_kb=20)
This loops from quality 85 downward in steps of 5 until the output fits inside 20KB, then saves it.
JavaScript (browser Canvas API)
// Works in any modern browser - no libraries needed
async function compressToTargetKB(file, targetKB = 20) {
const targetBytes = targetKB * 1024;
const img = await createImageBitmap(file);
const canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
let quality = 0.85;
let blob;
do {
blob = await new Promise(res =>
canvas.toBlob(res, 'image/jpeg', quality)
);
quality -= 0.05;
} while (blob.size > targetBytes && quality > 0.05);
return blob; // ready to download or upload
}
The Canvas API's toBlob method encodes the image at whatever JPEG quality you pass. The loop keeps reducing quality until the blob fits. This is exactly the approach the tool above uses.
How it works under the hood
When you drop an image, the browser draws it onto an invisible HTML canvas element. The tool then calls canvas.toBlob() with progressively lower JPEG quality values - starting high and stepping down - until the resulting file is 20KB or smaller.
No pixels are removed; the image keeps its original dimensions. What changes is how much JPEG compression is applied. Higher compression = more visual artefacts, but also a much smaller file. The W3C Canvas 2D API makes all of this possible without any server or plugin.
Because everything runs locally, your photo never leaves your device. The page doesn't log, store, or upload anything.
When to use this tool - and when not to
Good fits
- Government or official forms that specify a maximum of 20KB for ID photos or documents.
- Job application portals with tight size caps on profile pictures.
- School or exam registration sites that reject files over 20-50KB.
- Quickly reducing file size for email attachments without installing software.
Not the right tool if…
- You need to print the image - 20KB JPEG quality is too low for clean print output. Use the original file for printing.
- You need transparency - JPEG doesn't support transparent backgrounds. Use PNG and a higher size limit instead.
- You need to resize to specific pixel dimensions alongside compressing - resize first, then use this tool to hit your KB target.
- The source image is already a very small file (e.g. a 15KB icon) - compressing it further may degrade it severely with no real benefit.
Need to work with structured data files rather than images? Check out the JSON Beautifier to format and validate JSON, or the JSON Minifier to shrink JSON payload size for faster API responses.
Takeaway: hitting a strict 20KB limit used to mean wrestling with Photoshop's "Save for Web" dialog or a chain of desktop apps - now it takes four clicks. Use the tool above, download your compressed image, and move on.