DEV Community

Vijay Kanna
Vijay Kanna

Posted on

I Built a Tool That Resizes Images to an Exact KB Target Instead of a Quality Slider

Every image resizer I tried had the same problem: you drag a "quality" slider and hope the output lands under whatever limit you actually need.

That's fine if you're optimizing a blog header. It's useless if a government exam portal tells you "signature must be under 20KB" and rejects your file three times before you land close enough by trial and error.

So I built a resizer that works backward from a target file size instead of a quality percentage. You type "50KB," it iterates compression internally until the output is as close as possible to that number, then gives you the file.

How it works, roughly:

  • Runs entirely in the browser (Canvas API + a binary search over quality/dimension steps)
  • No upload to a server, so it's fast and doesn't touch your original file
  • Converges on a target size within a few passes instead of guessing What surprised me building it: The hard part wasn't the compression — it was handling images that can't hit the target no matter how much quality you strip, without silently returning garbage. Had to add a floor where it tells you "can't go below X without destroying the image" instead of pretending it succeeded.

It's part of a small toolkit I've been building — ResizeHub — free, no login, no watermark. This particular tool came directly out of watching people in exam-prep forums complain about signature/photo size rejections.

Curious if others have hit the same "quality slider vs. target size" mismatch in other contexts — video export, PDF compression, etc. What's your workaround been?

Top comments (0)