<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abhigyan Saikia</title>
    <description>The latest articles on DEV Community by Abhigyan Saikia (@abhigyannsaikia).</description>
    <link>https://dev.to/abhigyannsaikia</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4160981%2F74fa7ee7-47e6-416d-931b-26af8bc54473.jpg</url>
      <title>DEV Community: Abhigyan Saikia</title>
      <link>https://dev.to/abhigyannsaikia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhigyannsaikia"/>
    <language>en</language>
    <item>
      <title>How to Compress an Image to an Exact KB Size in the Browser (Free, No Upload)</title>
      <dc:creator>Abhigyan Saikia</dc:creator>
      <pubDate>Sun, 04 Oct 2026 06:13:49 +0000</pubDate>
      <link>https://dev.to/abhigyannsaikia/how-to-compress-an-image-to-an-exact-kb-size-in-the-browser-free-no-upload-8be</link>
      <guid>https://dev.to/abhigyannsaikia/how-to-compress-an-image-to-an-exact-kb-size-in-the-browser-free-no-upload-8be</guid>
      <description>&lt;p&gt;Upload forms don't ask for "80% quality". They ask for "photo under 50KB". And every mainstream compressor hands you a quality slider and wishes you luck — compress, check size, adjust, repeat.&lt;br&gt;
There are three ways to hit an exact KB target. Here's all of them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option 1: ImageMagick (one line)&lt;/strong&gt;&lt;br&gt;
If you're on a machine with ImageMagick installed:&lt;br&gt;
magick input.jpg -define jpeg:extent=50KB output.jpg&lt;br&gt;
The jpeg:extent define binary-searches the quality for you. Change 50KB to whatever the form wants. Fast, scriptable, exact.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option 2: Do it in the browser with Canvas&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The same binary-search idea works client-side. Sketch of the approach:&lt;br&gt;
async function compressToKB(file, targetKB) {&lt;br&gt;
  const bitmap = await createImageBitmap(file);&lt;br&gt;
  const canvas = document.createElement('canvas');&lt;br&gt;
  canvas.width = bitmap.width;&lt;br&gt;
  canvas.height = bitmap.height;&lt;br&gt;
  canvas.getContext('2d').drawImage(bitmap, 0, 0);&lt;/p&gt;

&lt;p&gt;let low = 0.05, high = 0.95, best = null;&lt;br&gt;
  for (let i = 0; i &amp;lt; 8; i++) {           // 8 rounds is plenty&lt;br&gt;
    const q = (low + high) / 2;&lt;br&gt;
    const blob = await new Promise(r =&amp;gt; canvas.toBlob(r, 'image/jpeg', q));&lt;br&gt;
    if (blob.size &amp;lt;= targetKB * 1024) { best = blob; low = q; }&lt;br&gt;
    else { high = q; }&lt;br&gt;
  }&lt;br&gt;
  // If quality alone can't reach it, shrink dimensions and repeat.&lt;br&gt;
  return best;&lt;br&gt;
}&lt;br&gt;
Eight iterations converge fast. If the lowest quality still overshoots, halve the dimensions and run again — pixel count dominates file size.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option 3: Use a tool that does this already (disclosure: I built it)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I got tired of doing the slider dance for exam forms, so I built ToolKB — you type the exact KB target (20KB, 50KB, 100KB, anything up to 10MB) and it runs the binary search above entirely in your browser.&lt;br&gt;
Why in-browser matters: these are identity documents — passport photos, signatures. Nothing uploads anywhere; you can watch the Network tab and see zero outgoing transfers. No signup, no watermark, no daily limit.&lt;br&gt;
Handy presets if you're filling Indian exam forms:&lt;br&gt;
Signature to 20KB — SSC/IBPS signature spec (10–20KB)&lt;br&gt;
Photo to 50KB — SSC GD / IBPS photo range&lt;br&gt;
Photo to 200KB — UPSC photo spec&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The rule of thumb&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;File size ≈ pixels × quality. If your 12MP phone photo won't squeeze into 50KB without turning to mush, don't just crush the quality — halve the dimensions first (that quarters the pixels), then compress. Sharper result, same file size.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
