<?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: Digambar Patil</title>
    <description>The latest articles on DEV Community by Digambar Patil (@digambar_patil_62486f6b40).</description>
    <link>https://dev.to/digambar_patil_62486f6b40</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%2F4249036%2Fab372ade-92ce-4321-b114-37ec8cd01162.png</url>
      <title>DEV Community: Digambar Patil</title>
      <link>https://dev.to/digambar_patil_62486f6b40</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/digambar_patil_62486f6b40"/>
    <language>en</language>
    <item>
      <title>How we built an image compressor that keeps files in the browser</title>
      <dc:creator>Digambar Patil</dc:creator>
      <pubDate>Tue, 17 Nov 2026 06:32:04 +0000</pubDate>
      <link>https://dev.to/digambar_patil_62486f6b40/how-we-built-an-image-compressor-that-keeps-files-in-the-browser-2g1o</link>
      <guid>https://dev.to/digambar_patil_62486f6b40/how-we-built-an-image-compressor-that-keeps-files-in-the-browser-2g1o</guid>
      <description>&lt;p&gt;An image compressor doesn't need a server to receive the original file. On Wezual Tools, we use browser APIs to decode the image, resize it when requested, and encode a new file. The original image stays on the device during compression.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decode, draw, and encode
&lt;/h2&gt;

&lt;p&gt;The input is a browser &lt;code&gt;File&lt;/code&gt;. After decoding the image, we draw it onto a canvas sized for the output. If the user sets a maximum width, we scale down while preserving the aspect ratio. This can reduce the output size before we adjust quality.&lt;/p&gt;

&lt;p&gt;Canvas encoding is asynchronous. We check the returned MIME type because a browser can fall back to another format when it can't encode the requested one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quality&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBlob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blob&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"This browser cannot encode the selected format."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quality&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Treat a size limit as a measurement
&lt;/h2&gt;

&lt;p&gt;A quality setting is an input to the encoder. It doesn't predict a file size. For size targets, we encode at candidate quality settings and inspect each resulting &lt;code&gt;Blob&lt;/code&gt;'s byte length. If a file can't meet the chosen limit at those settings, reducing its pixel dimensions or switching to a lossy format can help. PNG doesn't respond to the quality slider like JPEG or WebP does.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test more than the happy path
&lt;/h2&gt;

&lt;p&gt;Try a large photo, a transparent PNG, and a batch of files. Compare the output type, dimensions, and byte size. Be explicit about transparency when exporting to JPEG, which has no alpha channel. Large images also deserve attention because decoding consumes memory based on pixel dimensions even when the input file is small.&lt;/p&gt;

&lt;p&gt;You can try this workflow in the &lt;a href="https://tools.wezual.com/tools/image-compressor/" rel="noopener noreferrer"&gt;Wezual Image Compressor&lt;/a&gt;. I'm sharing it as part of the team behind Wezual Tools.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>javascript</category>
      <category>tools</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
