<?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: Subarnadip Pal</title>
    <description>The latest articles on DEV Community by Subarnadip Pal (@subarnadip_pal_2e355c24f2).</description>
    <link>https://dev.to/subarnadip_pal_2e355c24f2</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3527228%2Fccaa7631-225e-4650-ae57-6a3182ccf24e.jpg</url>
      <title>DEV Community: Subarnadip Pal</title>
      <link>https://dev.to/subarnadip_pal_2e355c24f2</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/subarnadip_pal_2e355c24f2"/>
    <language>en</language>
    <item>
      <title>Build a client-side image compressor in 5 minutes</title>
      <dc:creator>Subarnadip Pal</dc:creator>
      <pubDate>Thu, 25 Sep 2025 20:09:36 +0000</pubDate>
      <link>https://dev.to/subarnadip_pal_2e355c24f2/build-a-client-side-image-compressor-in-5-minutes-pp3</link>
      <guid>https://dev.to/subarnadip_pal_2e355c24f2/build-a-client-side-image-compressor-in-5-minutes-pp3</guid>
      <description>&lt;p&gt;You can compress images directly in the browser using a tiny SDK (no servers needed).&lt;br&gt;
Add one script, wire a file input, and call a single function.&lt;br&gt;
Works with JPEG/WEBP/PNG, supports target KB, resizing, and auto-quality.&lt;br&gt;
What we’ll build&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A simple page where users:&lt;/li&gt;
&lt;li&gt;Pick an image&lt;/li&gt;
&lt;li&gt;Choose target size and format&lt;/li&gt;
&lt;li&gt;Click “Compress”&lt;/li&gt;
&lt;li&gt;Preview the result and download it&lt;/li&gt;
&lt;li&gt;Why client-side compression?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Privacy:&lt;/strong&gt; Images never leave the device&lt;br&gt;
&lt;strong&gt;Speed:&lt;/strong&gt; Instant feedback, no network roundtrips&lt;br&gt;
&lt;strong&gt;Simplicity:&lt;/strong&gt; No servers, queues, or rate limits&lt;/p&gt;

&lt;p&gt;Add the SDK Drop this script into your page (hosted by ImgSmaller):&lt;br&gt;
The SDK exposes a global object: ImgSmaller.SDK with one main method: compress.&lt;/p&gt;

&lt;p&gt;Add basic HTML We’ll need a file input, some controls, and a place to preview results.&lt;/p&gt;

&lt;p&gt;Wire up the JavaScript A few lines to load the image, compress it, and show the preview.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Customize the output You can pass more options to compress:&lt;/em&gt;&lt;br&gt;
targetKB: desired size in KB (default 100)&lt;br&gt;
mime: 'image/jpeg' | 'image/webp' | 'image/png'&lt;br&gt;
width, height: optional resize (numbers)&lt;br&gt;
auto: true|false — prioritize visual quality over exact size&lt;br&gt;
background: '#ffffff' (useful for JPEG when source has transparency)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;const res = await ImgSmaller.SDK.compress(file, { targetKB: 80, mime: 'image/webp', width: 1280, // optional resize auto: true, // quality-first background: '#fff', // fill background for JPEG });&lt;/p&gt;

&lt;p&gt;Demo: &lt;a href="https://codepen.io/subarnadip/pen/qEbOeXg" rel="noopener noreferrer"&gt;https://codepen.io/subarnadip/pen/qEbOeXg&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How it works (under the hood)&lt;/p&gt;

&lt;p&gt;Loads the image into a Canvas&lt;br&gt;
Optionally resizes&lt;br&gt;
Runs a quick binary search on the quality to approximate your target size&lt;br&gt;
Produces a Blob + Object URL for preview/download&lt;br&gt;
All in the browser—no server calls required&lt;br&gt;
Caveats&lt;/p&gt;

&lt;p&gt;Very large images may be memory-heavy in low-end devices; consider resizing first&lt;br&gt;
PNG is lossless; “quality” doesn’t apply. Use JPEG/WEBP for size targeting&lt;br&gt;
WEBP support depends on the browser (most modern browsers support it)&lt;br&gt;
That’s it! You just built a client-side image compressor with a few lines of JavaScript. If you want a production-ready compressor with bulk support, exact KB presets, and a user-friendly UI, try ImgSmaller:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://imgsmaller.com" rel="noopener noreferrer"&gt;https://imgsmaller.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Credits&lt;/p&gt;

&lt;p&gt;SDK: &lt;a href="https://imgsmaller.com/sdk/imgsmaller.js" rel="noopener noreferrer"&gt;https://imgsmaller.com/sdk/imgsmaller.js&lt;/a&gt; (MIT)&lt;br&gt;
Demo snippet works on any static host or code playground&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>productivity</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
