<?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: Hau Vo Phuoc</title>
    <description>The latest articles on DEV Community by Hau Vo Phuoc (@hauvophuoc).</description>
    <link>https://dev.to/hauvophuoc</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%2F1558620%2F76aa6a0d-e239-4a77-825f-2ca9d4b5db8f.jpg</url>
      <title>DEV Community: Hau Vo Phuoc</title>
      <link>https://dev.to/hauvophuoc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hauvophuoc"/>
    <language>en</language>
    <item>
      <title>Safari silently returns PNG for WebP, and other lessons from a zero-upload image tool</title>
      <dc:creator>Hau Vo Phuoc</dc:creator>
      <pubDate>Fri, 04 Dec 2026 19:33:40 +0000</pubDate>
      <link>https://dev.to/hauvophuoc/safari-silently-returns-png-for-webp-and-other-lessons-from-a-zero-upload-image-tool-1f37</link>
      <guid>https://dev.to/hauvophuoc/safari-silently-returns-png-for-webp-and-other-lessons-from-a-zero-upload-image-tool-1f37</guid>
      <description>&lt;p&gt;Every chat app has its own sticker rules, and they don't agree. WhatsApp wants exactly 512 x 512 px, WebP, 100 KB or less. Discord wants a 320 x 320 PNG. Telegram wants one side at exactly 512 px and doesn't care about the other. Slack has no stickers at all, only emoji under 128 KB.&lt;/p&gt;

&lt;p&gt;I make a sticker app, and "why won't WhatsApp take my sticker?" is a question I keep running into. Instead of explaining pixel and size rules every time, I built a small free checker and fixer that runs in the browser: &lt;a href="https://getpaplo.com/sticker-checker" rel="noopener noreferrer"&gt;getpaplo.com/sticker-checker&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The one hard rule I set: the images never leave the browser. No upload, no server, no account. Here is how the browser pipeline works, and the platform quirks that shaped it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading a file without trusting it
&lt;/h2&gt;

&lt;p&gt;The checker looks at four things per file: pixel size, format, transparency and file size.&lt;/p&gt;

&lt;p&gt;Pixel size comes from &lt;code&gt;createImageBitmap&lt;/code&gt;, with one detail that matters for phone photos:&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;const&lt;/span&gt; &lt;span class="n"&gt;bitmap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;createImageBitmap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;imageOrientation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'from-image'&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;p&gt;&lt;code&gt;from-image&lt;/code&gt; applies the EXIF rotation, so the width and height are the ones people actually see, not the sensor's.&lt;/p&gt;

&lt;p&gt;Transparency is a pixel scan: draw the bitmap to a canvas, read the alpha channel, stop at the first pixel below 255. JPGs skip the scan because they have no alpha channel. A file with no transparent pixel is a photo with a background, not a sticker, so the tool refuses to turn it into a white square and says it needs background removal first.&lt;/p&gt;

&lt;p&gt;Format comes from the MIME type, but animation does not show up there. So the tool reads a few bytes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Animated WebP:&lt;/strong&gt; &lt;code&gt;RIFF....WEBPVP8X&lt;/code&gt;, then bit &lt;code&gt;0x02&lt;/code&gt; of the flags byte.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;APNG:&lt;/strong&gt; an &lt;code&gt;acTL&lt;/code&gt; chunk before the first &lt;code&gt;IDAT&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GIF:&lt;/strong&gt; count image descriptors (&lt;code&gt;0x2C&lt;/code&gt;) while skipping extension blocks; more than one means animated.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Animated files are checked but not fixed. Re-encoding animation in the browser is a different project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixing: fit, convert, then shrink
&lt;/h2&gt;

&lt;p&gt;Fitting is "contain, never crop". For exact-size targets the image is centred on a transparent canvas. Telegram is the odd one out: the longest side becomes 512 px and the other keeps its proportion, with no padding.&lt;/p&gt;

&lt;p&gt;Then the file has to get under the size limit. The browser's encoder takes a quality from 0 to 1, so the tool steps down until the result fits:&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;const&lt;/span&gt; &lt;span class="no"&gt;QUALITY_STEPS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;0.92&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.85&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.78&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;stepQuality&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;quality&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="no"&gt;QUALITY_STEPS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;last&lt;/span&gt; &lt;span class="o"&gt;=&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="n"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;await&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;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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;limit&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="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;last&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&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;p&gt;Best quality first, so a sticker only loses as much as it has to. PNG has no quality knob, so when a PNG is too big and the app also accepts WebP (Telegram, Signal), it switches to WebP. When the app only takes PNG (Discord, Slack), the tool says the file is too large instead of quietly wrecking it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Safari problem
&lt;/h2&gt;

&lt;p&gt;This was the biggest surprise. WhatsApp requires WebP, and the obvious browser API is:&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="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="n"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'image/webp'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.8&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;p&gt;Chrome and Firefox return a WebP. Safari returns a PNG. No error, just a different format. You can only find out by checking:&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;const&lt;/span&gt; &lt;span class="n"&gt;nativeWebp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'canvas'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toDataURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'image/webp'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'data:image/webp'&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;p&gt;On iPhone that means the main use case, WhatsApp stickers, would silently produce the wrong file. The fix is libwebp compiled to WebAssembly, through &lt;a href="https://github.com/jamsinclair/jSquash" rel="noopener noreferrer"&gt;jSquash&lt;/a&gt;. Two choices kept it light:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Load it only when needed.&lt;/strong&gt; The encoder is fetched the first time someone presses Fix on a browser without native WebP encoding. Everyone else never downloads it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Serve it from my own origin.&lt;/strong&gt; The &lt;code&gt;.js&lt;/code&gt; and &lt;code&gt;.wasm&lt;/code&gt; files are copied out of &lt;code&gt;node_modules&lt;/code&gt; at build time and cached for a week. No CDN, so the "nothing leaves your browser" promise stays simple to check.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There is a SIMD build and a plain one. A tiny &lt;code&gt;WebAssembly.validate&lt;/code&gt; call on a SIMD opcode picks which to load.&lt;/p&gt;

&lt;h2&gt;
  
  
  A ZIP writer with no dependency
&lt;/h2&gt;

&lt;p&gt;Fixing 30 stickers and downloading them one by one is miserable, so the tool bundles them into a ZIP. PNG and WebP files are already compressed, so deflate would gain almost nothing. A "store only" ZIP is just local headers, the raw bytes, a central directory and an end record, plus a CRC-32 per file. No dependency needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd tell anyone building a tool like this
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Put the limits in one data file.&lt;/strong&gt; The same numbers feed the checker and a written guide on my site, and a test fails if they drift apart. Platforms change these limits quietly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test the format you got, not the one you asked for.&lt;/strong&gt; Safari taught me that.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Say what you won't fix.&lt;/strong&gt; "Needs a cutout" and "too large for PNG" are more useful than a broken file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can try the checker at &lt;a href="https://getpaplo.com/sticker-checker" rel="noopener noreferrer"&gt;getpaplo.com/sticker-checker&lt;/a&gt;. If a platform has changed its limits, or you have hit other strange &lt;code&gt;canvas.toBlob&lt;/code&gt; behaviour, tell me in the comments.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webassembly</category>
      <category>webdev</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
