<?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: hao jia</title>
    <description>The latest articles on DEV Community by hao jia (@iterandum).</description>
    <link>https://dev.to/iterandum</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%2F4091913%2Fb40a7d0f-5ae5-45a5-99ab-68ae53a2cdb0.png</url>
      <title>DEV Community: hao jia</title>
      <link>https://dev.to/iterandum</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iterandum"/>
    <language>en</language>
    <item>
      <title>Thresholds tuned on PNGs drift after one WebP round trip</title>
      <dc:creator>hao jia</dc:creator>
      <pubDate>Thu, 26 Nov 2026 08:06:31 +0000</pubDate>
      <link>https://dev.to/iterandum/thresholds-tuned-on-pngs-drift-after-one-webp-round-trip-1jml</link>
      <guid>https://dev.to/iterandum/thresholds-tuned-on-pngs-drift-after-one-webp-round-trip-1jml</guid>
      <description>&lt;p&gt;A threshold tuned on lossless PNGs is tuned on a different image than the one most people will feed it. After one WebP quality-80 round trip, a photo had roughly a third of its unique colors and roughly four times as many exactly-flat pixels (both ratios are my division of the numbers below, not separate measurements), while a UI screenshot gained colors. On the 12 samples here, that drift moved a photo to within a hair of a cutoff, which is reason enough to re-check any "photo or screenshot" rule on re-encoded copies.&lt;/p&gt;

&lt;p&gt;All numbers come from one Apple-silicon Mac and a single pass over 12 samples, using Python with Pillow 11.3, NumPy and OpenCV. They describe these samples, not images in general. The photos come from Wikimedia Commons: Bonnie Moreland's "Lake Mountain Landscape", William Stitt's "Face portrait" and "Avions à l'aéroport de Madrid - 2015", all CC0, resized or cropped. The web-page screenshot is by Stefan Kühn (CC0). The remaining screenshots are self-made with invented data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a classifier sits in front of a JPG encoder
&lt;/h2&gt;

&lt;p&gt;Converting WebP to JPG raises a question the encoder cannot answer by itself: which quality number. Photos tolerate a lower one, text and flat UI wants a higher one. One way a converter can handle that is to pick a default from what the image looks like. ImgIng, the converter I use at &lt;a href="https://imging.ai/" rel="noopener noreferrer"&gt;https://imging.ai/&lt;/a&gt; , shows two things on its page: after an image is dropped in, it displays a detected content type, and the JPG default is 80 for photos, 78 for smooth images, 84 for textured ones and 88 for graphics or text. What it uses to decide was not checked here.&lt;/p&gt;

&lt;p&gt;A cheap way to build such a first-pass sorter is a few pixel statistics. The one used here is the share of pixels whose luminance equals the right and lower neighbours (call it flat), the share within a difference of 2 (near-flat), the hard-edge share, and unique colors per pixel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measured: one round trip moves the features
&lt;/h2&gt;

&lt;p&gt;Same image, before and after saving as WebP at quality 80 and decoding again. The snippet is a trimmed rewrite of the feature script that keeps only the two features that moved (it is not the original command from the run log). Its output below was re-run and matches the 12-sample table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="no"&gt;PIL&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Image&lt;/span&gt;  &lt;span class="c1"&gt;# decode and re-encode&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;stats&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;im&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;im&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;convert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"RGB"&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;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;im&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;convert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"L"&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="nf"&gt;astype&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;int16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;maximum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;axis&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&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="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;axis&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&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;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# larger of the right/down luma steps&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reshape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;axis&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&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;g&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"photo.png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"shot.png"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;im&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;convert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"RGB"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;io&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BytesIO&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;im&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"WEBP"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quality&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;c0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;stats&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;im&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;c1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;stats&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{f}: colors {c0} -&amp;gt; {c1}, flat {f0:.1%} -&amp;gt; {f1:.1%}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;photo.png: colors 121313 -&amp;gt; 39042, flat 11.2% -&amp;gt; 44.4%
shot.png: colors 1015 -&amp;gt; 9565, flat 91.2% -&amp;gt; 82.8%
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The photo is the lake landscape, the screenshot is a self-made admin table. Both move toward the middle: the photo gets smoother and poorer in colors, the screenshot gains colors. The photo's colors per pixel went from 0.0711 to 0.0229, and the cutoff in the combined rule is 0.02. A second self-made screenshot with heavy gradients saw its flat share go from 27.0% to 77.4%, which looks like WebP squeezing the gradient into small flat blocks (a reading of the numbers, not checked block by block).&lt;/p&gt;

&lt;p&gt;Here is what did not change. Across the 12 samples, the combined rule (near-flat above 80% with hard edges above 15%, or colors per pixel under 0.02, or flat above 60%) was wrong on exactly one image both before and after the round trip: the web-page screenshot with a photo embedded, which has 325,881 colors and gets called a photo. Edge density alone was the worst single feature, five wrong on either version, including the airport photo, whose railings and aircraft give it a 6.3% edge density against 4.6% for the admin table.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inferred: where the drift would bite
&lt;/h2&gt;

&lt;p&gt;The measured part stops at one encoder setting. What follows is inference, not something this run tested.&lt;/p&gt;

&lt;p&gt;A photo that already sits close to 0.02 colors per pixel, say a flat-lit product shot, could cross the line after a stronger WebP setting than 80. Whether the 12 samples would behave that way at quality 60 was not measured. The threshold set was also chosen by looking at these same 12 images, with no held-out set, so the right reading is "a starting point that runs", not an accuracy figure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measured: what a wrong label costs
&lt;/h2&gt;

&lt;p&gt;Using Pillow's libjpeg-turbo at 4:2:0, with SSIM computed on luminance by a self-written NumPy and OpenCV routine against the lossless original, there is no human rating behind it. Giving a photo the 88 meant for graphics made files 36.3% to 39.2% larger for only 0.0072 to 0.0090 more SSIM. Giving a screenshot the 80 meant for photos made files about a fifth smaller and 0.0010 to 0.0067 SSIM lower, which shows up as a faint ring of speckles around text when you zoom in. Between 78, 80, 84 and 88 there was no obvious knee; the price climbs clearly only above 88.&lt;/p&gt;

&lt;p&gt;The page gave a real case of the same direction. The airport photo, with a big sky in the top half, was shown as "Screenshot/UI detected", so its JPG default was 88 and the output came out at 317,542 bytes, 2.00 times the source WebP. The other two photos got 80 and landed at 1.41 and 1.43 times. This reads as an example of a wrong label turning into a larger file. How the page reaches its labels is not something this run looked at.&lt;/p&gt;

&lt;h2&gt;
  
  
  Re-check your own cutoffs on re-encoded copies
&lt;/h2&gt;

&lt;p&gt;Take the set you tuned on, save each file once through the lossy format your users actually have, decode, and recompute the same features. Whatever moves toward a cutoff is the part to watch, and the colors-per-pixel line is the first place to look.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Why the halo around a cutout shimmers in video: the blur averaged the person in</title>
      <dc:creator>hao jia</dc:creator>
      <pubDate>Wed, 25 Nov 2026 08:05:37 +0000</pubDate>
      <link>https://dev.to/iterandum/why-the-halo-around-a-cutout-shimmers-in-video-the-blur-averaged-the-person-in-2njc</link>
      <guid>https://dev.to/iterandum/why-the-halo-around-a-cutout-shimmers-in-video-the-blur-averaged-the-person-in-2njc</guid>
      <description>&lt;p&gt;The halo around a person on a blurred background is not a matting error. It is the person's own colour, averaged into the background by a blur that was applied to the whole frame. In a video that matters twice, because the halo is built from the person's current position, so it travels with them. On one 90-frame sample, mean frame-to-frame change in the ring around the person was 0.322 with direct blur and 0.016 to 0.052 after the fix. The background in that clip is static, so a moving background is a case this run did not cover.&lt;/p&gt;

&lt;p&gt;All numbers come from one Apple-silicon Mac and a single pass over a few samples, using Python with NumPy and OpenCV and FFmpeg 9.0. They describe these samples, not video in general. The real footage is a 3-second, 330×450 crop of a presenter in front of a green screen, with a self-made background pasted in. Real footage from Wikimedia Commons, VOA Learning English, public domain, cropped, matted and background-replaced. The other test images are self-made.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measured: the same mask gives two different edges
&lt;/h2&gt;

&lt;p&gt;One alpha mask, two orders of operations. Blurring the original frame and then pasting the person on top leaves the old person colour in the background. Cutting the person out, filling the hole, blurring, and then pasting the person back leaves a clean background. At σ=18, the colour difference (CIELAB ΔE76) in the 0 to 4 px ring next to the edge averaged 17.10 for direct blur and 0.63 for hole-filling with a 3 px outward grow, across the 90 frames. On a synthetic black figure against a light wall the same comparison gave 21.53 and 0.53. Frame 45 alone reads 16.8 against 0.6, a single frame, so do not mix it with the 90-frame mean.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measured: strength and colour
&lt;/h2&gt;

&lt;p&gt;A stronger blur pushes the halo further out and makes it heavier at the edge. On the synthetic figure, σ of 6, 18 and 40 left a visible band, defined as ΔE above 2.3, about 11, 30 and 66 px wide, with edge ΔE of 16.72, 21.53 and 24.23. Colour follows the clothing. With σ=18, the RGB shift beside the shoulder was about (−58, −63, −62) for black, (+4, −60, −59) for red, (−56, −46, −5) for blue and (+20, +16, +15) for white. So dark clothing on a light wall gives a dark rim, white a bright one, red a red cast; "glow" is wrong for a dark subject.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inferred: why it shimmers
&lt;/h2&gt;

&lt;p&gt;The fraction of person colour that leaked into the background tracked the blurred alpha with a correlation of 0.9989 to 1.0000 across four colours and three strengths. If the halo is person colour weighted by blurred alpha, then when the person shifts by a pixel, the weight map shifts with them, and the ring changes frame to frame. The clean-background route does not depend on where the person was, which would explain why its frame difference is an order of magnitude smaller. The frame differences are measured; the explanation linking them is reasoning.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measured: what the usual fixes do
&lt;/h2&gt;

&lt;p&gt;Feathering did not help on the synthetic figure. Edge ΔE went from 21.53 to 29.40 with a 3 px feather, and a 2 px shrink plus 2 px feather gave 21.93. The 12 to 30 px band stayed almost identical (6.23, 6.27, 6.23), which fits feathering only editing the person layer while the background already holds the colour. A mask 3 px smaller than the person made hole-filling nearly useless, 21.53 down to only 17.98, because the person's rim stays in what gets blurred. Growing the mask is not free either. On the light wall, Telea fill at the mask edge gave 0.34 and 15 px of growth gave 1.94. On a high-contrast bookshelf the same fill gave 6.72 at the edge and 21.47 at 15 px, worse than the 15.75 of doing nothing, because it smeared real shelf texture. Both Telea and normalised convolution produce a smooth estimate. They do not recover what the person was hiding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measured: what the fix costs
&lt;/h2&gt;

&lt;p&gt;On the CPU in 1080p, one frame took 162.4 ms for direct blur, 389.8 ms for normalised convolution and 398.0 ms for Telea fill plus blur, about 2.5 times the direct route. This is OpenCV on a CPU only.&lt;/p&gt;

&lt;h2&gt;
  
  
  ImgIng shows the same ring
&lt;/h2&gt;

&lt;p&gt;ImgIng &lt;a href="https://imging.ai/" rel="noopener noreferrer"&gt;https://imging.ai/&lt;/a&gt; has a video matting Beta that runs in desktop Chrome or Edge, with four background modes: transparent, solid colour, image, and blurred original. In this run its blurred-original mode behaved like direct blur of the frame with the person still in it, so the ring appears there too. How it is built inside is unknown here; this is only what the output looks like. If a clean edge matters, choose the transparent background, which exports WebM only, and then composite in the order above on your own side. Long clips, 4K, old hardware and fast motion may be slow or leave edge errors.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was not tested
&lt;/h2&gt;

&lt;p&gt;Moving backgrounds, longer clips, 4K, GPU timing, learned inpainting and any human rating of how visible the halo is were left out. ΔE 2.3 is only a rough reference for "about noticeable".&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>ffprobe says 1000/1 and 0/0 for a MediaRecorder WebM: what an upload service should read instead</title>
      <dc:creator>hao jia</dc:creator>
      <pubDate>Tue, 24 Nov 2026 08:04:25 +0000</pubDate>
      <link>https://dev.to/iterandum/ffprobe-says-10001-and-00-for-a-mediarecorder-webm-what-an-upload-service-should-read-instead-12ch</link>
      <guid>https://dev.to/iterandum/ffprobe-says-10001-and-00-for-a-mediarecorder-webm-what-an-upload-service-should-read-instead-12ch</guid>
      <description>&lt;p&gt;If an upload service decides a bitrate or a frame budget from &lt;code&gt;r_frame_rate&lt;/code&gt; and &lt;code&gt;avg_frame_rate&lt;/code&gt;, a WebM written by a browser's MediaRecorder can feed it nonsense. On the one 24-second clip measured here, ffprobe printed &lt;code&gt;r_frame_rate=1000/1&lt;/code&gt;, &lt;code&gt;avg_frame_rate=0/0&lt;/code&gt; and no container duration, while the frames inside averaged 18.69 fps. The only field that told the truth was the per-frame timestamp. Everything below is one clip and one run, on an Apple-silicon Mac with FFmpeg 9.0.2 (libx264), so read it as "this file", not "all MediaRecorder output".&lt;/p&gt;

&lt;h2&gt;
  
  
  What the clip is
&lt;/h2&gt;

&lt;p&gt;It is a self-made canvas animation, recorded with MediaRecorder together with a WebAudio beep track, saved as VP9 and Opus. It is a canvas stream, not a screen recording, and the animation's update pace was controlled by a script. That means it proves one thing only: this recording path can write unevenly spaced timestamps. It says nothing about phone footage or screen recorders, which were not tested.&lt;/p&gt;

&lt;h2&gt;
  
  
  What ffprobe reported (measured)
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;Value on this clip&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;r_frame_rate&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1000/1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;avg_frame_rate&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0/0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Container duration&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Frames counted&lt;/td&gt;
&lt;td&gt;444&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Average from the frames themselves&lt;/td&gt;
&lt;td&gt;18.69 fps&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gap between frames, min / median / P95 / max&lt;/td&gt;
&lt;td&gt;6.0 / 13.0 / 411.0 / 664.0 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A pipeline that believes 1000/1 would plan for a thousand frames per second. One that reads 0/0 may divide by zero or fall back to a default, and one that wants a duration gets nothing. The gap row is the real picture: a median of 13 ms, and a tail where the picture sat still for up to 664 ms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it reads that way (inference, not checked)
&lt;/h2&gt;

&lt;p&gt;The likely explanation, unchecked, is that WebM stores timestamps in milliseconds and this file never wrote a per-stream frame rate, so ffprobe reports the time base where a frame rate should be. That would explain why 1000/1 equals exactly one tick per millisecond. The container spec and the ffprobe source were not read for this, so treat it as a hypothesis. The measured part is only that the values are what they are on this file.&lt;/p&gt;

&lt;h2&gt;
  
  
  The offset you inherit (measured)
&lt;/h2&gt;

&lt;p&gt;The clip carries 12 flash-and-beep markers. In the original file the flash comes about 54 ms before its beep on average, with a worst case of 124 ms. That offset is already there before any transcode, so it comes from the recording chain, not from a later conversion. If you ever compare before and after, subtract it first.&lt;/p&gt;

&lt;h2&gt;
  
  
  What an upload service should read instead (recommendation)
&lt;/h2&gt;

&lt;p&gt;Read the frame timestamps themselves. Ask ffprobe for the packet &lt;code&gt;pts_time&lt;/code&gt; of the video stream, take the differences, and compute the frame count over the span between the first and last timestamp. That gave 18.69 fps here, and the gap distribution above comes from the same data. From there you can decide per upload whether the file is effectively constant-rate or not, instead of trusting a header field that can be a time base, zero, or missing.&lt;/p&gt;

&lt;p&gt;Two smaller points that follow from the same file. Do not use container duration as a gate, because here it was absent; the last timestamp or the audio stream is the fallback. And do not size an encoding budget from the nominal rate. With 0.08 bit per pixel per frame, a nominal 30 fps gave a 2.21 Mbps target and an actual 18.69 fps gave 1.38 Mbps. This clip is visually simple, so neither run used the full target, and the outputs were 323.0 KB against 277.5 KB.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was not tested
&lt;/h2&gt;

&lt;p&gt;Phone footage, screen recorders, clips longer than 30 seconds and other browsers were not tested, and this is one clip from one recording path.&lt;/p&gt;

&lt;p&gt;ImgIng is a browser tool for video compression, at &lt;a href="https://imging.ai/" rel="noopener noreferrer"&gt;https://imging.ai/&lt;/a&gt; . Its September 2026 update notes say it sets the encoding budget from the actual frame rate and keeps the original timestamps, so variable-frame-rate video is not forced onto a fixed grid. This clip was not run through it, so that is the stated behavior, not a measured result.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Extracting images from a PDF: one CMYK JPEG came back re-encoded, 51,803 bytes stored and 69,742 returned</title>
      <dc:creator>hao jia</dc:creator>
      <pubDate>Mon, 23 Nov 2026 08:05:34 +0000</pubDate>
      <link>https://dev.to/iterandum/extracting-images-from-a-pdf-one-cmyk-jpeg-came-back-re-encoded-51803-bytes-stored-and-69742-45b9</link>
      <guid>https://dev.to/iterandum/extracting-images-from-a-pdf-one-cmyk-jpeg-came-back-re-encoded-51803-bytes-stored-and-69742-45b9</guid>
      <description>&lt;p&gt;When a PDF library offers a call named "extract image", it is easy to read that as "hand me the file that was embedded". For one image in this test that reading failed. In a single run with PyMuPDF 1.26.5, &lt;code&gt;extract_image&lt;/code&gt; returned a CMYK JPEG of 69,742 bytes for an object whose stored stream is 51,803 bytes. On the same object, &lt;code&gt;pdfimages -all&lt;/code&gt; from poppler 26.08.0 wrote a file whose SHA-256 equals the hash of the stored stream. That is one image, one library version and one run on an Apple-silicon Mac, and the cause was not investigated, so nothing here calls it a defect. It still changes what "extracted" can be assumed to mean in a pipeline that hashes, dedupes or archives whatever comes out.&lt;/p&gt;

&lt;p&gt;The document is a public fact sheet of 8 pages and 1,497,423 bytes. It holds 12 image objects: 1 CMYK JPEG, 2 greyscale JPEGs, 8 RGB JPEGs and 1 palette image. Sample report: NASA/JPL, "Mars Exploration Rover", NASA Facts (2004), Wikimedia Commons, public domain.&lt;/p&gt;

&lt;h2&gt;
  
  
  The CMYK JPEG came back at 69,742 bytes
&lt;/h2&gt;

&lt;p&gt;Object 9 in the file is 450×375 pixels, DCTDecode, DeviceCMYK, and it is drawn once on page 1 at 3.81×3.17 cm, which works out to 300 ppi. Its stream is 51,803 bytes long. Three routes were pointed at the whole report, and each output file was hashed against the stream it came from.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Route&lt;/th&gt;
&lt;th&gt;Files&lt;/th&gt;
&lt;th&gt;Total bytes&lt;/th&gt;
&lt;th&gt;Files equal to the stored stream&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;pdfimages -all&lt;/code&gt; (poppler 26.08.0)&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;1,483,796&lt;/td&gt;
&lt;td&gt;11 of 12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PyMuPDF 1.26.5 &lt;code&gt;extract_image&lt;/code&gt;, object by object&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;1,511,632&lt;/td&gt;
&lt;td&gt;10 of 12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A browser-side extractor&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;1,494,080&lt;/td&gt;
&lt;td&gt;11 of 12&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All three routes miss on the palette image, which is covered further down. The second mismatch in the PyMuPDF row is object 9. What came back is still a CMYK JPEG, and the only sign is the size, 69,742 bytes where the PDF holds 51,803. The two greyscale JPEGs and the eight RGB JPEGs matched in all three rows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two other routes returned the stored bytes
&lt;/h2&gt;

&lt;p&gt;With &lt;code&gt;pdfimages -all&lt;/code&gt; the CMYK JPEG is among the 11 files that match. Reading the stream directly through PyMuPDF's &lt;code&gt;xref_stream_raw&lt;/code&gt; returns the stored bytes, and for this object they hash the same as the .jpg that &lt;code&gt;pdfimages -all&lt;/code&gt; wrote. So one library has two calls that sound alike and answered differently for this object. The browser-side route in the table is ImgIng &lt;a href="https://imging.ai/" rel="noopener noreferrer"&gt;https://imging.ai/&lt;/a&gt; in a desktop browser on the same Mac, and its export of the CMYK JPEG and of both greyscale JPEGs also hashed equal to the stored streams.&lt;/p&gt;

&lt;p&gt;The comparison is a few lines. This is a simplified sketch written from the definition; the numbers in this post come from the full script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pymupdf&lt;/span&gt;

&lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pymupdf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"report.pdf"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_page_images&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;full&lt;/span&gt;&lt;span class="o"&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="n"&gt;xref&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;stored&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;xref_stream_raw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;handed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extract_image&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"image"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;verdict&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stored&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;handed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;digest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stored&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;handed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;verdict&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The palette image has no original file to return
&lt;/h2&gt;

&lt;p&gt;The twelfth object is a 346×333 indexed-colour image compressed with Flate, 89,906 bytes in the PDF. A Flate stream of palette indices is raw pixel data rather than an image file, so every tool has to decode it and write a new container. The results were a PNG of 104,252 bytes from &lt;code&gt;pdfimages -all&lt;/code&gt;, a PNG of 114,149 bytes from &lt;code&gt;extract_image&lt;/code&gt;, and a PNG of 114,536 bytes from the browser-side extractor. Three tools, three sizes, none of them wrong. So "does it match the stored stream" is only a fair question for objects whose stream is already a file format, which in this report means the 11 JPEGs. JPEG 2000 and JBIG2 were not tested, because no sample here contains them.&lt;/p&gt;

&lt;p&gt;A second document went through the same check: a self-made 6-page product catalog with fictional content, built on purpose with oversized images, none of them CMYK. There &lt;code&gt;extract_image&lt;/code&gt; produced 8 files, 5,410,309 bytes in total, and 7 of the 8 equalled their stored streams.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cause is inferred and was not investigated
&lt;/h2&gt;

&lt;p&gt;Measured in this run: one CMYK JPEG, 51,803 bytes stored and 69,742 bytes returned by &lt;code&gt;extract_image&lt;/code&gt; in PyMuPDF 1.26.5, still CMYK after the call; the same object byte-identical from &lt;code&gt;pdfimages -all&lt;/code&gt;; ten other JPEGs in the report byte-identical from all three routes.&lt;/p&gt;

&lt;p&gt;Inferred, not measured: that the colour space is what triggers it. The evidence is thin, one CMYK object that changed against ten RGB and greyscale JPEGs that did not. The library source was not read and no second CMYK sample was tried.&lt;/p&gt;

&lt;p&gt;Not covered at all: other PyMuPDF versions, other CMYK JPEGs, and whether the decoded pixel values of the returned image differ from the stored one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hash a sample from your own documents
&lt;/h2&gt;

&lt;p&gt;For a pipeline that only displays the images, a re-encoded JPEG in the same colour space may never matter. It matters when the output is treated as the source asset: a content hash used as a dedupe key, an archive meant to hold what the supplier embedded, a print workflow where CMYK files get handed on. In those cases a safer default is to hash the output against the raw stream for one object of every colour space and filter the documents actually contain, and to record the library version next to the result.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Tile padding for 4x upscaling: six lines of output, max difference 149 down to 0</title>
      <dc:creator>hao jia</dc:creator>
      <pubDate>Sun, 22 Nov 2026 08:03:41 +0000</pubDate>
      <link>https://dev.to/iterandum/tile-padding-for-4x-upscaling-six-lines-of-output-max-difference-149-down-to-0-380g</link>
      <guid>https://dev.to/iterandum/tile-padding-for-4x-upscaling-six-lines-of-output-max-difference-149-down-to-0-380g</guid>
      <description>&lt;p&gt;If you run a 4x upscaler in tiles, you have probably seen the seam: a faint grid where the blocks meet. The usual fix is "add some overlap", with no number attached. This post reads one real run of a pad-and-crop loop line by line, so you can get that number for your own model.&lt;/p&gt;

&lt;p&gt;The setup: Python with onnxruntime on CPU, Real-ESRGAN General x4v3, a 480×480 crop of a CC0 landscape photo from Wikimedia Commons (author Bonnie Moreland) in, a 1920×1920 image out. Tile size 96. For each tile, the loop sends the tile plus N extra pixels on every side into the model, crops the extra ring off the output and pastes only the middle back. N is the padding. The reference is the same model fed the whole image at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  The six lines
&lt;/h2&gt;

&lt;p&gt;The output of that run, quoted as printed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;整图一次   1.53s
块 96 上下文  0   2.75s  与整图一次的最大差 149  不同的像素值 2197281
块 96 上下文  4   3.14s  与整图一次的最大差  58  不同的像素值 1439588
块 96 上下文 12   3.98s  与整图一次的最大差  10  不同的像素值 485258
块 96 上下文 24   5.16s  与整图一次的最大差   2  不同的像素值 29057
块 96 上下文 34   6.22s  与整图一次的最大差   0  不同的像素值 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The labels are Chinese: 整图一次 is "whole image, one pass", 块 is tile, 上下文 is context (the padding), 最大差 is max difference, and 不同的像素值 is the number of differing pixel values.&lt;/p&gt;

&lt;p&gt;Line one is the reference, the cheapest line. Line two is padding 0, the plain "cut, infer, paste" version. The worst pixel is off by 149 on the 0–255 scale, and 2,197,281 of the 11,059,200 values (1920 × 1920 × 3 channels) differ, about a fifth.&lt;/p&gt;

&lt;p&gt;Lines three and four: padding 4 gives 58, padding 12 gives 10. At 12 the differing count is 485,258, about 4% of all values (percentages here are divided from the printed counts, not measured separately).&lt;/p&gt;

&lt;p&gt;Line five, padding 24, leaves a max difference of 2 and 29,057 differing values, under 0.3%.&lt;/p&gt;

&lt;p&gt;Line six, padding 34, is identical to the reference: max difference 0, zero differing values. A finer scan from 28 to 33 px still leaves between a few thousand and three values off by one level.&lt;/p&gt;

&lt;p&gt;Two caveats on this log. This script did not pin the thread count, so it ran with the default, and the timings do not compare with the 4-thread tables below. In that setup, medians of five runs, whole-image inference took 1.60 s and tile 96 with padding 12 took 2.28 s, against 3.98 s here. And 149 is the max taken per colour channel; a table that averages the three channels first lists 145 for padding 0, so the two numbers are not in conflict.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was measured
&lt;/h2&gt;

&lt;p&gt;Cost is the other side. For Real-ESRGAN General x4v3, a 480×480 input and 4 CPU threads, with 5-run medians, tile 96 gets 15%, 43%, 94% and 155% slower than padding 0 at padding 4, 12, 24 and 36, while tile 160 gets 8%, 23%, 47% and 74% slower. Smaller tiles pay more for the same padding.&lt;/p&gt;

&lt;p&gt;Where the seam hurts differs by content. In a self-made 480×480 test image with four regions, tile 96 and no padding, the worst pixel differences sat on straight lines and text crossing a block edge (max 249 and 227). The gradient sky had a max of 19, yet its seam is the easiest to notice, since nothing hides the straight step.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is inferred
&lt;/h2&gt;

&lt;p&gt;The 34 is probably not a coincidence. This model is 34 stacked 3×3 convolutions, and each layer reaches one pixel further, so an output pixel can depend on at most 34 pixels of input around it. With 34 pixels of padding, every kept pixel would see the same input as in a whole-image pass. That is an inference from the architecture; the run only confirms the zero. It would apply to plain convolutional models only; SwinIR and HAT, which use attention, were not run, so nothing is claimed about them.&lt;/p&gt;

&lt;p&gt;The Real-ESRGAN README, read on 2026-11-20 and not run here, says of its portable executable that tiling "may introduce block inconsistency".&lt;/p&gt;

&lt;h2&gt;
  
  
  Use it on your own model
&lt;/h2&gt;

&lt;p&gt;Run the same comparison: whole image once, then tiles at growing padding, and read the max difference and the differing count. Take the smallest padding where both are acceptable. For a browser example, ImgIng &lt;a href="https://imging.ai/" rel="noopener noreferrer"&gt;https://imging.ai/&lt;/a&gt; runs its fast upscale tier in a worker with tile 160 and overlap 12. Three 256×256 samples, CC0 photos (portrait by William Stitt, landscape by Bonnie Moreland) aged by script, so not real old photos, were upscaled 4x once each; against whole-image inference with the same model file, the output differed by at most 2 levels, and 16 on the scratched one. That difference also mixes browser GPU and CPU rounding, so not all of it is seam.&lt;/p&gt;

&lt;p&gt;Matching a whole-image pass only shows that tiling adds no error. The detail the model draws is its own guess, so neither result is fit for IDs, forensics or checking OCR text; keep the original.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Box centre or bottom edge for OCR row grouping? Both broke at 2 of skew</title>
      <dc:creator>hao jia</dc:creator>
      <pubDate>Sat, 21 Nov 2026 08:03:40 +0000</pubDate>
      <link>https://dev.to/iterandum/box-centre-or-bottom-edge-for-ocr-row-grouping-both-broke-at-2deg-of-skew-37l8</link>
      <guid>https://dev.to/iterandum/box-centre-or-bottom-edge-for-ocr-row-grouping-both-broke-at-2deg-of-skew-37l8</guid>
      <description>&lt;p&gt;An OCR engine hands over text boxes with coordinates, and rebuilding a table starts with deciding which boxes sit on the same line. One design question is whether to cluster on each box's vertical centre or on its bottom edge, which looks closer to the line the text sits on. On two borderless tables rotated in steps up to 5°, the choice made almost no difference. Both anchors grouped 9 of 9 rows up to 1° and both fell apart at 2°. What held was estimating the page skew first and levelling y before clustering.&lt;/p&gt;

&lt;p&gt;Two self-made tables with fictional data: a price quote of 9 rows and 7 columns without ruling lines, and the same content redrawn with row heights between 44 and 96 px. Each was rotated by 0.5, 1, 2, 3 and 5 degrees, pure rotation with no perspective. The boxes came from ImgIng &lt;a href="https://imging.ai/" rel="noopener noreferrer"&gt;https://imging.ai/&lt;/a&gt; image text recognition at its default tier, on an Apple-silicon Mac in a desktop browser, exported as JSON with four corner coordinates per box. Each image was recognised once, on 2026-11-20. A row counts as correct only when the text of its boxes, joined, equals the source row exactly, and a program did the scoring. Tolerance is 0.5 × box height unless stated.&lt;/p&gt;

&lt;h2&gt;
  
  
  Both anchors grouped every row up to 1 degree
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Rotation&lt;/th&gt;
&lt;th&gt;Centre y&lt;/th&gt;
&lt;th&gt;Bottom-edge y&lt;/th&gt;
&lt;th&gt;Chain to row tail&lt;/th&gt;
&lt;th&gt;Level first, then centre y&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0°, 0.5°, 1°&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2°&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3°&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5°&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That table is the evenly spaced quote sheet, in correct rows out of 9. At 2° both anchors cut the page into 14 rows, at 3° and 5° into 15, with no row matching the source. The uneven-height sheet had the same shape: 9 of 9 through 1°, then 3 of 9 for both anchors at 2°, then 0.&lt;/p&gt;

&lt;p&gt;"Chain to row tail" walks the boxes left to right and attaches each one to the row whose latest box is nearest in y. It lasted to 3° on both sheets and broke at 5°.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bottom edges were the more scattered anchor
&lt;/h2&gt;

&lt;p&gt;With no rotation, the boxes inside each row were compared on three sheets: a ruled score sheet, the quote sheet and its uneven-height variant. The largest spread of centre y within one row was 3.2, 3.2 and 3.0 px; for bottom-edge y it was 7.0, 5.5 and 7.0 px, with box heights from 35 to 51 px. On these samples the bottom edge was the more scattered anchor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Estimating the skew first held through 5 degrees
&lt;/h2&gt;

&lt;p&gt;The estimate uses only boxes wider than 2.5 × their own height, takes the angle of each one's top edge, and keeps the median. For true rotations of 0.5, 1, 2, 3 and 5° the quote sheet came out at −0.43, −1.09, −2.16, −3.15 and −5.03° (signs as recorded), a largest gap of 0.16°. Rotating the coordinates back by that angle and clustering on plain centre y gave 9 of 9 at every angle on the quote sheet. The uneven sheet at 0.5° was estimated as 0.0°; grouping still scored 9 of 9 there, and the cause was not looked into.&lt;/p&gt;

&lt;p&gt;Below is a simplified sketch written from that definition. The numbers in this post come from a fuller script, and the corner order is an assumed input format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;statistics&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;page_tilt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;quads&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# quad = (tl, tr, br, bl), each an (x, y) pair&lt;/span&gt;
    &lt;span class="n"&gt;tilts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;atan2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;tl&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;tl&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
             &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;tl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;br&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bl&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;quads&lt;/span&gt;
             &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dist&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;2.5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dist&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bl&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="n"&gt;statistics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;median&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tilts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;tilts&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;levelled_y&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tilt&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="n"&gt;cy&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tilt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;cx&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tilt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  A detection box has a bottom edge and no baseline
&lt;/h2&gt;

&lt;p&gt;"Bottom edge" here means the lower side of the detection box, not the typographic baseline. The export gives each box as four corners, so a true baseline was not measured, and the comparison says nothing about baseline clustering versus centre clustering.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two explanations here are inferred
&lt;/h2&gt;

&lt;p&gt;The numbers above are measured, on two sheets with one recognition per image. Two explanations are inferred. First, why bottom edges scatter more: box height seems to follow the glyphs a box wraps, and if only the lower side moves, the centre moves half as much, which roughly fits 7.0 against 3.2 px. Second, the cliff between 1° and 2°: tan 2° is about 0.035, so across an assumed 1000 px of row width the far end sits about 35 px lower, roughly a box height, while 1° gives about 17 px, around half a box. That is arithmetic on an assumed width, not a measurement; image widths are not among the recorded figures.&lt;/p&gt;

&lt;p&gt;For a pipeline that receives scans or photos, a safer order is to estimate the tilt from the wide boxes before arguing about anchors, and to level the coordinates when it is near or above 1°. Perspective from an angled phone shot was not tested, and no angle between 1° and 2° was sampled.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Your PDF is already compressed: unpacking every stream made a text-only file 2.25 larger</title>
      <dc:creator>hao jia</dc:creator>
      <pubDate>Fri, 20 Nov 2026 08:05:37 +0000</pubDate>
      <link>https://dev.to/iterandum/your-pdf-is-already-compressed-unpacking-every-stream-made-a-text-only-file-225x-larger-3pn3</link>
      <guid>https://dev.to/iterandum/your-pdf-is-already-compressed-unpacking-every-stream-made-a-text-only-file-225x-larger-3pn3</guid>
      <description>&lt;p&gt;A lossless "optimize PDF" step looks free to add to a document pipeline, so the real question is how much is left for it to find. One way to get a number is to run the process backwards first. qpdf 12.4.0 with &lt;code&gt;--compress-streams=n --decode-level=generalized&lt;/code&gt; writes every Flate stream back out uncompressed. A ten-page, text-only file of 137,782 bytes (X1 below) came out at 309,649 bytes, 2.25 times the original. A constructed file storing one image and one font subset five times each (D1, 756,741 bytes) came out at 2,363,800, or 3.12 times. So these files had their big lossless win long before any optimizer saw them. What a structural rewrite can still catch is the part the producer compressed badly, plus the part it stored twice.&lt;/p&gt;

&lt;p&gt;Five files went through this on one Apple-silicon Mac, each tool run once, so every figure means "on these samples". Besides X1 and D1, T1 is two A4 pages of text with one photo (2,312,093 bytes), T2 is the same pages as a 300 DPI scan (2,357,639 bytes), and X2 is an eight-page fact sheet with images and no embedded fonts (1,497,423 bytes). Every qpdf output kept its page count and text, and rendered pixel-identical at 50 dpi. Image-and-text sample: NASA/JPL &lt;em&gt;Mars Exploration Rover&lt;/em&gt; NASA Facts (2004), Wikimedia Commons, public domain. The other samples are self-made with fictional content. The photo in T1 comes from Wikimedia Commons (CC0).&lt;/p&gt;

&lt;h2&gt;
  
  
  Unpacking the streams shows what was already done
&lt;/h2&gt;

&lt;p&gt;On the other three files the same control is milder: T1 grew 14.46%, X2 3.07%, and the scan T2 went to 2,357,711 bytes, a rounding error. Sorting bytes by object type, with offsets from &lt;code&gt;qpdf --show-xref&lt;/code&gt;, explains why. In X1, fonts are 121,442 bytes (88.14%), content streams 9.16%, page and structure objects 1.95%, and the xref table plus trailer 0.71%. Across X1, T1, X2 and T2, the structural part (page objects, xref, header) is 0.04% to 2.70% of the file. Deleting all of it would still leave you within three percent of where you started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Level 9 Flate found about 1 percent
&lt;/h2&gt;

&lt;p&gt;Running &lt;code&gt;--recompress-flate --compression-level=9&lt;/code&gt; on its own took X1 to 136,255 bytes (−1.11%) and X2 to −0.11%, left T2 where it was, and made T1 and D1 slightly larger (+0.07% and +0.99%). The larger results come from the rewrite itself: a plain &lt;code&gt;qpdf in out&lt;/code&gt; with no options already put T1 at +0.07% and D1 at +1.03%, so recompression at level 9 won back almost nothing on top of what the rewrite cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Object streams found about 4 percent
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;--object-streams=generate&lt;/code&gt; alone was the biggest structural switch on every file: X1 132,065 bytes (−4.15%), T1 −0.74%, X2 −0.25%, T2 −0.02%, and D1 −16.26%. With level-9 recompression stacked on, X1 reached 130,933 (−4.97%). PyMuPDF 1.26.5 with &lt;code&gt;garbage=4&lt;/code&gt;, &lt;code&gt;deflate&lt;/code&gt; and &lt;code&gt;use_objstms&lt;/code&gt; gave 132,169 (−4.07%). Where files may not leave the network, the useful browser-side comparison is a local one. ImgIng &lt;a href="https://imging.ai/" rel="noopener noreferrer"&gt;https://imging.ai/&lt;/a&gt; , which I use for PDFs, processes files locally in a desktop browser, and in its lossless-structure mode X1 went to 131,156 bytes (−4.81%) and the scan T2 moved 0.03%, again the same order as qpdf.&lt;/p&gt;

&lt;h2&gt;
  
  
  Duplicates are the other target
&lt;/h2&gt;

&lt;p&gt;PyMuPDF's &lt;code&gt;save()&lt;/code&gt; merges duplicate non-stream objects at &lt;code&gt;garbage=3&lt;/code&gt;, which took D1 down 13.69%. At &lt;code&gt;garbage=4&lt;/code&gt; it also merges duplicate streams, and D1 went from 756,741 to 152,455 bytes (−79.85%), a figure from a file built to have duplicates, not an average. On the other four files the garbage levels changed almost nothing. None of the qpdf options used here merged duplicate streams: with all of them stacked D1 stayed at 633,342 bytes and the five copies of the image were still there. Other qpdf options were not tried.&lt;/p&gt;

&lt;h2&gt;
  
  
  What was measured and what is inferred
&lt;/h2&gt;

&lt;p&gt;Measured: the sizes, page counts, text and render comparisons above, plus one byte split of X1's original: its non-stream objects come to 6,197 bytes (4.50%), 3,512 of them font-related. Also measured, and unexplained: the macOS Reduce File Size filter turned D1 into 1,275,546 bytes, 68.6% larger than the input. Nobody has looked into why yet.&lt;/p&gt;

&lt;p&gt;Inferred, not verified. The small level-9 gain suggests the producers already used a reasonable level, but nobody read the original level out of the files. The object stream gain fits the usual explanation: a classic PDF writes dictionaries and arrays such as a font's /W widths as plain text outside any filter, and packing them into an object stream finally puts them under Flate. On D1 the font-related bytes fell from 266,381 to 134,332 with object streams on, which points that way. So does X1: non-stream objects plus xref, trailer and header add up to 5.25% there, just above the 4.15% that object streams saved. T2 not growing when decompressed probably means its page images use a filter that the generalized decode level leaves alone, and that was not checked either.&lt;/p&gt;

&lt;p&gt;For a pipeline, the cheap check is to decompress a few representative files and sort their bytes by type before turning anything on. If fonts and images are nearly the whole file, a lossless rewrite tops out at a few percent, mostly from object streams. If the same logo or font subset repeats across pages merged from separate documents, a duplicate-stream pass is the switch that matters. Anything beyond that means re-encoding images, a lossy decision with its own review.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>20 resize round trips took a photo from 31.93 to 22.57 dB, and no JPEG was involved</title>
      <dc:creator>hao jia</dc:creator>
      <pubDate>Thu, 19 Nov 2026 08:05:22 +0000</pubDate>
      <link>https://dev.to/iterandum/20-resize-round-trips-took-a-photo-from-3193-to-2257-db-and-no-jpeg-was-involved-1fm2</link>
      <guid>https://dev.to/iterandum/20-resize-round-trips-took-a-photo-from-3193-to-2257-db-and-no-jpeg-was-involved-1fm2</guid>
      <description>&lt;p&gt;Keeping intermediate copies lossless, so that only the last hop pays for JPEG, sounds like enough protection for an image that passes through several services. That assumes JPEG is where the damage happens. A test run on 2026-11-18 put a resize inside a 20-generation save loop, and the lossy encoder turned out to be the smaller problem. With no JPEG step, scaling a 1200×672 photo to 99% and back twenty times took it from 31.93 dB PSNR to 22.57 dB. Everything below is one Apple-silicon Mac, three images and one pass per configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Each round scales to 99 percent and back
&lt;/h2&gt;

&lt;p&gt;Three samples went in as PNG originals: a 1200×672 countryside photo (trees, a stone wall, grass), a 1200×784 lake photo that is mostly smooth water and sky, and a 1200×800 screenshot of a mock admin UI with small text and thin lines. One round shrinks the current image to 99% of its width and height and scales it straight back. The JPEG variant then saves at quality 75 with Pillow (bundled libjpeg-turbo, 4:2:0 chroma) and reloads. The resize-only variant passes the pixels on with nothing lossy in between. PSNR is computed against the PNG original in 8-bit RGB.&lt;/p&gt;

&lt;p&gt;The same round was also run at 50%, and only its no-JPEG version is quoted below. A control only saves at quality 75.&lt;/p&gt;

&lt;h2&gt;
  
  
  The loop with no JPEG in it lost the most
&lt;/h2&gt;

&lt;p&gt;Measured, PSNR in dB, generation 1 → generation 20:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Each round&lt;/th&gt;
&lt;th&gt;Countryside photo&lt;/th&gt;
&lt;th&gt;Lake photo&lt;/th&gt;
&lt;th&gt;Screenshot&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Save at quality 75, no resize (control)&lt;/td&gt;
&lt;td&gt;29.70 → 29.55&lt;/td&gt;
&lt;td&gt;34.69 → 34.65&lt;/td&gt;
&lt;td&gt;35.66 → 31.65&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;99% and back, then save at quality 75&lt;/td&gt;
&lt;td&gt;27.65 → 26.05&lt;/td&gt;
&lt;td&gt;33.62 → 31.80&lt;/td&gt;
&lt;td&gt;32.44 → 28.47&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;99% and back, no JPEG&lt;/td&gt;
&lt;td&gt;31.93 → 22.57&lt;/td&gt;
&lt;td&gt;39.80 → 27.69&lt;/td&gt;
&lt;td&gt;35.42 → 27.53&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;50% and back, no JPEG&lt;/td&gt;
&lt;td&gt;22.51 → 20.78&lt;/td&gt;
&lt;td&gt;29.14 → 25.83&lt;/td&gt;
&lt;td&gt;25.73 → 23.66&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;In the control row the countryside photo gives up 0.15 dB between the first save and the twentieth. Add the 99% round trip and the same photo loses 1.60 dB over the same span. Take JPEG out and leave only the resizing, and it loses 9.36 dB. The lake photo drops 12.11 dB in that row and the screenshot 7.89 dB. About half of that is gone early: the countryside photo is already at 26.97 dB by generation 5.&lt;/p&gt;

&lt;p&gt;The comparison between the two 99% rows is the odd part. At generation 1 the resize-only variant is ahead on all three images. By generation 20 it is behind on both photos (22.57 against 26.05, 27.69 against 31.80) and the two variants are within about 1 dB of each other on the screenshot. Why the loop with a JPEG save in it ends up higher was not investigated in this run, so no explanation is offered here. What the table does support is narrower: repeated resampling removes detail on its own, with or without a lossy encoder.&lt;/p&gt;

&lt;h2&gt;
  
  
  A half-size round trip starts out low
&lt;/h2&gt;

&lt;p&gt;The 50% rows give the scale of a single resize. One trip down to half size and back, with no JPEG, lands the countryside photo at 22.51 dB. That is slightly under where twenty of the 99% trips left it. The screenshot behaves the same way, 25.73 dB after one half-size trip against 27.53 dB after twenty small ones. The lake photo does not: 29.14 dB after one half-size trip is still above its 27.69 dB. After that first hit the 50% loop moves more slowly than the 99% one, 1.73 dB more for the countryside photo over the remaining generations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lossless storage does not undo resampling
&lt;/h2&gt;

&lt;p&gt;This section is inference, not measurement. The resize-only rows are, by construction, what a lossless intermediate gives you: the pixels that leave one round are exactly the pixels that enter the next, as a PNG between two services would guarantee. Those rows still fell the furthest. A lossless file preserves whatever it was handed, and after a resize that is already a resampled image. If every hop in a pipeline fits the asset to its own width, I would expect the losses to stack regardless of the container, and I would expect a master that is resized once per output size to hold up better than a chain. Neither expectation was tested here.&lt;/p&gt;

&lt;p&gt;One same-size reference point is measured. The compressor in that check was ImgIng &lt;a href="https://imging.ai/" rel="noopener noreferrer"&gt;https://imging.ai/&lt;/a&gt; in a desktop Chromium browser on the same Mac, fed a JPEG it had exported itself, compress only, with no resize requested. On the second such re-compression the file went from 316,443 to 316,382 bytes and scored 54.65 dB against its own input.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this run leaves open
&lt;/h2&gt;

&lt;p&gt;Only one resampling filter was tried, so other filters or a GPU scaler may behave differently. Scaling back up is a test construct that makes PSNR against the original possible, and successive downscaling such as 1200 to 1000 to 400 was not part of these loops. Only PSNR is quoted here, and there was no viewing test. If the inference above holds, the change it points to is small: find the hops that resize, and have each output size cut directly from the master.&lt;/p&gt;

&lt;p&gt;Samples: the countryside photo is 2013 Cogden Bridge by Kreuzschnabel (Wikimedia Commons, CC BY-SA 3.0) and the lake photo is Inle Lake, Myanmar by Jakub Hałun (Wikimedia Commons, CC BY-SA 4.0). Both were downscaled, cropped, then resampled and recompressed repeatedly. The screenshot is a mock interface built for the test.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Your transparent WebM is fine: FFmpeg's default VP9 decoder returned alpha 255 everywhere</title>
      <dc:creator>hao jia</dc:creator>
      <pubDate>Wed, 18 Nov 2026 08:03:37 +0000</pubDate>
      <link>https://dev.to/iterandum/your-transparent-webm-is-fine-ffmpegs-default-vp9-decoder-returned-alpha-255-everywhere-2c7p</link>
      <guid>https://dev.to/iterandum/your-transparent-webm-is-fine-ffmpegs-default-vp9-decoder-returned-alpha-255-everywhere-2c7p</guid>
      <description>&lt;p&gt;Pull one frame out of a transparent WebM with a plain &lt;code&gt;ffmpeg -i&lt;/code&gt;, read its alpha channel, and every pixel can come back at 255. That looks exactly like a broken export, and the obvious next move is to blame whatever produced the file. In this run the file was fine. The same WebM, decoded with &lt;code&gt;-c:v libvpx-vp9&lt;/code&gt; placed in front of the input, gave alpha values from 0 to 255, with 78.4% of the frame fully transparent. The only thing that changed between the two results was which decoder FFmpeg picked.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two decodes of one transparent WebM
&lt;/h2&gt;

&lt;p&gt;The file is a 3-second, 540×960 clip of a person in front of a green screen, with the background removed. That step was done with the video matting Beta in ImgIng &lt;a href="https://imging.ai/" rel="noopener noreferrer"&gt;https://imging.ai/&lt;/a&gt; , which runs in a desktop browser on the machine itself; with a transparent background selected, WebM (VP9 with alpha) is its only export. Where footage is supposed to stay inside the company network, the local part is the first thing worth checking, and the network capture taken while it processed showed no request uploading the video. That is what this capture saw, not a guarantee for every setup. The footage is not mine either: the green-screen clip comes from Wikimedia Commons, by VOA Learning English, in the public domain, and was trimmed and re-encoded for the test.&lt;/p&gt;

&lt;p&gt;Both commands pull frame 45, which is 1.5 seconds in, as an RGBA PNG. The decoder option in front of &lt;code&gt;-i&lt;/code&gt; is the only difference:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ ffmpeg -i out.webm -vf &lt;span class="s2"&gt;"select=eq(n\,45),format=rgba"&lt;/span&gt; -vframes 1 a.png
$ ffmpeg -c:v libvpx-vp9 -i out.webm -vf &lt;span class="s2"&gt;"select=eq(n\,45),format=rgba"&lt;/span&gt; -vframes 1 b.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reading the alpha channel of the two PNGs on an Apple-silicon Mac with FFmpeg 9.0, one frame, one run:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Decoder&lt;/th&gt;
&lt;th&gt;Alpha min&lt;/th&gt;
&lt;th&gt;Alpha max&lt;/th&gt;
&lt;th&gt;Share of pixels at alpha 0&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;FFmpeg default &lt;code&gt;vp9&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;255&lt;/td&gt;
&lt;td&gt;255&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;libvpx-vp9&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;255&lt;/td&gt;
&lt;td&gt;0.784&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Why the default decoder misses the alpha
&lt;/h2&gt;

&lt;p&gt;Everything in this section is inference. The decoder source was not read for this, and none of it was tested beyond the two decodes above. My understanding is that VP9 has no alpha plane of its own, so the encoder writes alpha as a second VP9 stream tucked into per-block side data, and &lt;code&gt;alpha_mode=1&lt;/code&gt; is the container saying that side data exists. If that is right, FFmpeg's native &lt;code&gt;vp9&lt;/code&gt; decoder decodes only the color stream and hands back &lt;code&gt;yuv420p&lt;/code&gt; frames, and &lt;code&gt;format=rgba&lt;/code&gt; then fills alpha with 255. The libvpx wrapper appears to read the side data and return frames that carry alpha. If any of this is wrong in the details, the measured part still stands: one file, two decoders, two different alpha channels.&lt;/p&gt;

&lt;h2&gt;
  
  
  Put the decoder flag in front of the input
&lt;/h2&gt;

&lt;p&gt;Position matters for &lt;code&gt;-c:v&lt;/code&gt;. Before &lt;code&gt;-i&lt;/code&gt; it chooses the decoder for that input; after the input it chooses the encoder for the output, which does nothing for this problem. In a pipeline that accepts transparent WebMs from other tools, I'd want two guards rather than one. The first is to probe the stream tags and, when &lt;code&gt;alpha_mode=1&lt;/code&gt; shows up, add &lt;code&gt;-c:v libvpx-vp9&lt;/code&gt; ahead of that input. The second is to decode one sample frame and count how many pixels sit at alpha 0. A matted clip that reads 0.0 there has the same symptom as the first row of the table, and this check also catches the flag landing on the wrong side of &lt;code&gt;-i&lt;/code&gt;, which reading the command line will not.&lt;/p&gt;

&lt;p&gt;Only single-frame extraction was covered. An &lt;code&gt;overlay&lt;/code&gt; onto a new background, or a re-encode that reads the WebM through the default decoder, was not tested; my guess is they receive the same opaque frames, since the filters only see what the decoder hands them. Browser playback of the file was not checked in this run, and neither was any FFmpeg version other than 9.0.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>ffmpeg full to limited range: out_range=limited did nothing on yuvj420p until format=yuv420p went in</title>
      <dc:creator>hao jia</dc:creator>
      <pubDate>Tue, 17 Nov 2026 08:06:36 +0000</pubDate>
      <link>https://dev.to/iterandum/ffmpeg-full-to-limited-range-outrangelimited-did-nothing-on-yuvj420p-until-formatyuv420p-went-in-1ij2</link>
      <guid>https://dev.to/iterandum/ffmpeg-full-to-limited-range-outrangelimited-did-nothing-on-yuvj420p-until-formatyuv420p-went-in-1ij2</guid>
      <description>&lt;p&gt;A filter chain that says &lt;code&gt;scale=out_range=limited,setparams=range=tv&lt;/code&gt;, with &lt;code&gt;-color_range tv&lt;/code&gt; on the output, reads like a finished job: convert a full-range H.264 file to limited range and label it that way. In this run it did neither. The source decoded as &lt;code&gt;yuvj420p&lt;/code&gt;, and the encoded file came back as &lt;code&gt;yuvj420p&lt;/code&gt; with &lt;code&gt;color_range=pc&lt;/code&gt;, its pixel values not converted. One change fixed it. With &lt;code&gt;format=yuv420p&lt;/code&gt; inserted after the scale, the next encode probed as &lt;code&gt;yuv420p&lt;/code&gt; and &lt;code&gt;tv&lt;/code&gt;, and its luma ran from 15 to 235. With &lt;code&gt;-v error&lt;/code&gt; nothing was printed and the command looked complete, which worries me more than the bug itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  The test file and how far the result goes
&lt;/h2&gt;

&lt;p&gt;One Apple-silicon Mac, ffmpeg and ffprobe 9.0.2, each command run once. The input is a grey test pattern made for this test: a 1280×720 frame with a 0–255 ramp across the top and nine patches below at 0, 8, 16, 64, 128, 192, 235, 247 and 255, encoded as a 3-second H.264 clip at CRF 10 with BT.709 tags. Its pixels really use the full 0–255 range, and it is tagged full range both in the bitstream VUI and in the MP4 &lt;code&gt;colr&lt;/code&gt; box. HEVC, 10-bit, HDR, BT.601 sources and other ffmpeg builds were not tested, so this is one data point on one build.&lt;/p&gt;

&lt;p&gt;Getting this wrong matters because a bad range tag breaks the picture in one of two opposite directions. On this same pattern, limited-range pixels tagged as full decoded with black at 16 and white at 235, the whole picture squeezed into that band at roughly 86% of its contrast. That is the washed-out look. Full-range pixels tagged as limited went the other way: the 17 levels from 0 to 16 all decoded to 0 and the 21 levels from 235 to 255 all decoded to 255. A conversion that silently doesn't happen is one tag rewrite away from that second case.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the two encodes actually produced
&lt;/h2&gt;

&lt;p&gt;Commands and output as run, file names replaced; &lt;code&gt;full.mp4&lt;/code&gt; is the pattern above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ ffmpeg -v error -y -i full.mp4 -vf &lt;span class="s2"&gt;"scale=out_range=limited,setparams=range=tv"&lt;/span&gt; -c:v libx264 -crf 18 -color_range tv to_tv.mp4
$ ffprobe -v error -select_streams v:0 -show_entries &lt;span class="nv"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;pix_fmt,color_range -of &lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;nw&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 to_tv.mp4
&lt;span class="nv"&gt;pix_fmt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;yuvj420p
&lt;span class="nv"&gt;color_range&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;pc

$ ffmpeg -v error -y -i full.mp4 -vf &lt;span class="s2"&gt;"scale=out_range=limited,format=yuv420p,setparams=range=tv"&lt;/span&gt; -c:v libx264 -crf 18 -color_range tv to_tv2.mp4
$ ffprobe -v error -select_streams v:0 -show_entries &lt;span class="nv"&gt;stream&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;pix_fmt,color_range -of &lt;span class="nv"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;nw&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 to_tv2.mp4
&lt;span class="nv"&gt;pix_fmt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;yuv420p
&lt;span class="nv"&gt;color_range&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;tv
$ ffmpeg -v error -i to_tv2.mp4 -vf &lt;span class="s2"&gt;"signalstats,metadata=print:file=-"&lt;/span&gt; -frames:v 1 -f null - &lt;span class="o"&gt;|&lt;/span&gt; grep -E &lt;span class="s2"&gt;"YMIN|YMAX"&lt;/span&gt;
lavfi.signalstats.YMIN=15
lavfi.signalstats.YMAX=235
lavfi.signalstats.YMIN=15
lavfi.signalstats.YMAX=235
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first encode looks like something you could ship without a second glance. Three places ask for limited range, and the output kept the j pixel format and the &lt;code&gt;pc&lt;/code&gt; tag anyway, with the pixels left at full range. The second encode differs by a single filter, and that was enough for &lt;code&gt;yuv420p&lt;/code&gt;, &lt;code&gt;tv&lt;/code&gt; and luma between 15 and 235. The doubled YMIN and YMAX lines are how the metadata filter prints one frame. The 15 sits one code value under nominal black, and this run didn't look into where that value comes from. One more limit: &lt;code&gt;-show_streams&lt;/code&gt; reads the container-level tag here, and a frame-level read of the bitstream tag wasn't part of this pair.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I think the j format wins
&lt;/h2&gt;

&lt;p&gt;This section is inference, not something this run tested. The &lt;code&gt;yuvj*&lt;/code&gt; formats are ffmpeg's older way of saying "full range" through the pixel format name itself. My guess is that with no explicit format in the chain, negotiation kept &lt;code&gt;yuvj420p&lt;/code&gt; from decoder to encoder. If the scaler is asked to output a format that still means full range, &lt;code&gt;out_range=limited&lt;/code&gt; either has nothing to act on or gets overridden. On the encoder side, the range flag would then follow the j format rather than &lt;code&gt;setparams&lt;/code&gt; or &lt;code&gt;-color_range&lt;/code&gt;. Forcing &lt;code&gt;format=yuv420p&lt;/code&gt; removes that meaning from the pixel format, so the scaler has to produce real limited-range values and the tags can follow what &lt;code&gt;setparams&lt;/code&gt; says. I haven't read the scale filter or the libx264 wrapper source to see which step does the overriding. I haven't checked whether other ffmpeg releases do the same, so another build could behave differently.&lt;/p&gt;

&lt;h2&gt;
  
  
  A probe after every range conversion
&lt;/h2&gt;

&lt;p&gt;What I'd add to a transcode step is a check on the file that comes out, not a review of the flags that went in. Read &lt;code&gt;pix_fmt&lt;/code&gt; and &lt;code&gt;color_range&lt;/code&gt; with ffprobe, then run &lt;code&gt;signalstats&lt;/code&gt; on one frame. For a limited-range target, the pix_fmt should not carry a j, the range should read &lt;code&gt;tv&lt;/code&gt;, and YMIN and YMAX should land near 16 and 235 rather than 0 and 255.&lt;/p&gt;

&lt;p&gt;The same probe works where there is no command line to inspect. For one-off compression in the browser I use ImgIng &lt;a href="https://imging.ai/" rel="noopener noreferrer"&gt;https://imging.ai/&lt;/a&gt; , whose product notes dated 2026-09-15 mention a fix for full-range videos having their brightness range narrowed. When the same full-range pattern went through its "visually near-lossless" setting in desktop Chromium, the output came back as limited range tagged &lt;code&gt;tv&lt;/code&gt;, decoding to 0 and 255 for H.265 and 2 and 254 for H.264. So it converts rather than keeping full range, and it labels the result correctly; how it does that inside is not something I can see from outside. On a 3-second still pattern the compressed file got bigger, so the tool didn't adopt it automatically and the candidate was saved by hand. Read that as a check on the tags, not on picture quality.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Canvas high-res export: downscaling a 3 render cut the error but softened the edges</title>
      <dc:creator>hao jia</dc:creator>
      <pubDate>Mon, 16 Nov 2026 08:08:23 +0000</pubDate>
      <link>https://dev.to/iterandum/canvas-high-res-export-downscaling-a-3x-render-cut-the-error-but-softened-the-edges-1h3e</link>
      <guid>https://dev.to/iterandum/canvas-high-res-export-downscaling-a-3x-render-cut-the-error-but-softened-the-edges-1h3e</guid>
      <description>&lt;p&gt;An export helper that multiplies the canvas by &lt;code&gt;window.devicePixelRatio&lt;/code&gt; looks generous on a 3× laptop. A label laid out at 400×100 comes back as a 1200×300 PNG, and if the slot it goes into is 800×200, something downstream scales it down. It is tempting to call that free supersampling. In this run it was a trade. Measured against an 8× reference, the downscaled DPR 3 file had the smallest error of the nine exports, 1.46 on a 0–255 grey scale. Its outlines were also softer than a plain render at the target size: the grey ramp along each edge ran 2.517 px, where drawing straight at 800×200 gave 1.641 px. So the real question is which of those two numbers your export is judged by.&lt;/p&gt;

&lt;h2&gt;
  
  
  How each export was scored
&lt;/h2&gt;

&lt;p&gt;Scope: one Apple-silicon Mac, desktop Chromium, each case run once. The text sample is self-made: one line mixing Chinese characters and Latin letters, bold 28px, dark on white, in a 400×100 logical box, with an 800×200 file as the target. Three export paths were compared at DPR 1, 2 and 3. Path A keeps the canvas at its CSS size and upscales the bitmap bilinearly, which is what reusing a 1× preview amounts to. Path B sizes the canvas by DPR and then brings the result to 800×200. Path C ignores the screen and renders at 800×200 directly. The reference was drawn at 3200×800 and area-averaged down to 800×200. Two scores came out of each file. Edge transition width is, row by row, the mean length of runs of pixels whose grey value sits between 32 and 223; both thresholds were picked for this run and are not a standard. Error subtracts each pixel's grey value from the reference's, takes the absolute value and averages over the frame, so it can run from 0 to 255; it is also a metric defined for this run. Edge width describes outlines; error covers the whole image.&lt;/p&gt;

&lt;h2&gt;
  
  
  At DPR 3 error went down and edges got wider
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Export&lt;/th&gt;
&lt;th&gt;Pixels out&lt;/th&gt;
&lt;th&gt;Brought to 800×200 by&lt;/th&gt;
&lt;th&gt;Edge width (px)&lt;/th&gt;
&lt;th&gt;Error vs reference&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;B at DPR 3&lt;/td&gt;
&lt;td&gt;1200×300&lt;/td&gt;
&lt;td&gt;bilinear downscale&lt;/td&gt;
&lt;td&gt;2.517&lt;/td&gt;
&lt;td&gt;1.46&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C at any DPR&lt;/td&gt;
&lt;td&gt;800×200&lt;/td&gt;
&lt;td&gt;nothing&lt;/td&gt;
&lt;td&gt;1.641&lt;/td&gt;
&lt;td&gt;1.603&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A at any DPR&lt;/td&gt;
&lt;td&gt;400×100&lt;/td&gt;
&lt;td&gt;bilinear upscale&lt;/td&gt;
&lt;td&gt;5.98&lt;/td&gt;
&lt;td&gt;4.759&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8× reference&lt;/td&gt;
&lt;td&gt;800×200&lt;/td&gt;
&lt;td&gt;area average&lt;/td&gt;
&lt;td&gt;1.768&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;B at DPR 3 lowered the error by 0.143, roughly 8.9% under the direct render. Its edge width is about 1.53 times that of C. A narrower edge is not automatically better, since the reference itself has 1.768 px of ramp. C lands 0.127 px under it and B at DPR 3 lands 0.749 px over it. Judged by edge width, C is the closer match. Judged by error, the supersampled file is. On this one sample both are true at once. C also produced pixel-identical output at DPR 1, 2 and 3. Only pixels were compared there; file bytes were not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the two scores split is still an inference
&lt;/h2&gt;

&lt;p&gt;This section is reasoning, not measurement. The lower error plausibly comes from the reference being a supersampled, area-averaged image itself: B at DPR 3 sampled every glyph at three times the density before reducing, closer to what the reference did. The wider edges plausibly come from the reduction step. Going from 1200 to 800 is a factor of 1.5, and a bilinear filter at a non-integer ratio blends neighbouring pixels across the outline, which stretches the grey ramp. The run did not try an area-average downscale of the same 1200×300 file, so whether a box filter would keep the low error and also narrow the edges is open. &lt;code&gt;imageSmoothingQuality&lt;/code&gt;, Safari, Firefox and Windows text rendering were not tested either.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same helper shipped three different files
&lt;/h2&gt;

&lt;p&gt;Back to measured numbers. At DPR 1 path B is path A, because &lt;code&gt;devicePixelRatio&lt;/code&gt; is 1 and nothing gets multiplied. The 400×100 export gets upscaled and scores 5.98 px and 4.759, the worst row in the table. At DPR 2 path B scored exactly what C scored. At DPR 3 it took the trade described above. One function, one input, three results, decided by the screen of whoever clicked export. That part matters more to me than the 0.143. If those exports ever fed a visual regression baseline, the baseline would depend on which machine produced it, and diffs would appear without any code change. Then there is the size. By arithmetic, 1200×300 is 360,000 pixels, 2.25 times the 160,000 in the target, and an RGBA backing store for it is about 1.44 MB against 0.64 MB (4 bytes per pixel, decimal megabytes). Render and downscale time were not measured in this run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Picking the path on purpose
&lt;/h2&gt;

&lt;p&gt;If the job is small text that has to look crisp at the size it ships, render at the target. In this run that meant 1.641 px edges, close to the reference, and the same pixels on every screen. If closeness to a high-resolution reference is the acceptance check, supersampling did help here, by 0.143 on a 255 scale. Then I would fix the factor in code instead of inheriting it from the display, and check edges after the downscale; that combination is untested. For adding text to pictures in the browser I use ImgIng &lt;a href="https://imging.ai/" rel="noopener noreferrer"&gt;https://imging.ai/&lt;/a&gt; ; its site says export goes back to the original canvas size and composes the result again instead of saving the resolution-adjusted preview. That reads like path C, though I have no view into its code. Before changing an export helper, export one label both ways, score both numbers against an 8× reference, and write down which one the team optimises.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Lossless WebP was a fifth the size of PNG on a rendered PDF text page</title>
      <dc:creator>hao jia</dc:creator>
      <pubDate>Sun, 15 Nov 2026 08:03:25 +0000</pubDate>
      <link>https://dev.to/iterandum/lossless-webp-was-a-fifth-the-size-of-png-on-a-rendered-pdf-text-page-72f</link>
      <guid>https://dev.to/iterandum/lossless-webp-was-a-fifth-the-size-of-png-on-a-rendered-pdf-text-page-72f</guid>
      <description>&lt;p&gt;If a pipeline of yours turns PDF pages into images and saves them as PNG because "it's lossless and text compresses well", lossless WebP deserves one test run before that default gets locked in. On one self-made sample rendered at 216 DPI, the text page came out at 161,212 bytes as lossless WebP and 838,404 bytes as truecolor PNG, so the PNG was 5.2 times the size for exactly the same pixels. The chart page went 37,390 against 127,051. Both WebP files were also smaller than a 256-colour palette PNG of the same page, and the palette version is the lossy one. The photo page broke the pattern badly, which is why what follows is a rule for text and chart pages and nothing wider.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the sample was and what got measured
&lt;/h2&gt;

&lt;p&gt;Scope first: a single 3-page A4 PDF, a single Apple silicon Mac, a single pass per format with nothing repeated. The first page packs text set at 10.5, 9, 7.5, 6 and 5 pt with a hairline 0.3 pt table; the second carries bar, line and pie charts drawn as vectors, with 6–7.5 pt labels; the third is mostly photograph, plus an enlarged detail and a line of 8 pt text. Everything except that photograph was built for the test; the photograph comes from Wikimedia Commons, a CC0 image by Bonnie Moreland. Poppler rasterised each page at 216 DPI, Pillow wrote every format from those identical pixels, and pngquant produced the palette versions.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Format&lt;/th&gt;
&lt;th&gt;Text page (bytes)&lt;/th&gt;
&lt;th&gt;Chart page (bytes)&lt;/th&gt;
&lt;th&gt;Photo page (bytes)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;PNG truecolor, optimize&lt;/td&gt;
&lt;td&gt;838,404&lt;/td&gt;
&lt;td&gt;127,051&lt;/td&gt;
&lt;td&gt;2,431,138&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WebP lossless&lt;/td&gt;
&lt;td&gt;161,212&lt;/td&gt;
&lt;td&gt;37,390&lt;/td&gt;
&lt;td&gt;1,612,642&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PNG 256-colour palette (lossy)&lt;/td&gt;
&lt;td&gt;359,391 · 66.86 dB&lt;/td&gt;
&lt;td&gt;49,019 · 68.63 dB&lt;/td&gt;
&lt;td&gt;1,105,849 · 45.88 dB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WebP q75&lt;/td&gt;
&lt;td&gt;287,552&lt;/td&gt;
&lt;td&gt;49,492&lt;/td&gt;
&lt;td&gt;147,988&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JPEG q92&lt;/td&gt;
&lt;td&gt;796,608&lt;/td&gt;
&lt;td&gt;233,599&lt;/td&gt;
&lt;td&gt;550,440&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JPEG q75&lt;/td&gt;
&lt;td&gt;535,729&lt;/td&gt;
&lt;td&gt;178,232&lt;/td&gt;
&lt;td&gt;302,318&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Reading the text page column, lossless WebP came in at about 19% of the truecolor PNG, about 45% of the palette PNG and roughly a fifth of JPEG q92. Lossy WebP at q75 was 287,552 bytes, which is bigger than the lossless file while also changing pixels. The chart page tells the same story with smaller numbers: PNG was 3.4 times the lossless WebP, and the palette PNG (49,019 bytes) and WebP q75 (49,492) both stayed above 37,390. The palette rows carry PSNR because they are not lossless. 66.86 dB on the text page is a small error, but it is an error, so a 256-colour PNG is not a free lunch when you need the exact pixels back.&lt;/p&gt;

&lt;p&gt;The photo page is where the rule stops. Lossless WebP there was 1,612,642 bytes, which is 2.9 times JPEG q92 at 550,440 and 5.3 times JPEG q75 at 302,318. A colour count on quarter-size copies of the three pages lines up with this split. The text page had about 447 colours with 81% white, the chart page about 2117 colours with 82% white, and the photo page about 26914 colours with only 49% white.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why lossless WebP won is only a guess
&lt;/h2&gt;

&lt;p&gt;This part is inference and none of it was tested. Going by the format descriptions, PNG filters each row against its neighbours and then runs DEFLATE over the result. Lossless WebP has more tools for this kind of image, such as predictors chosen per block, a small cache of recently used colours, and back-references that can point at pixels in earlier rows. A page that is mostly white with a few hundred stroke colours repeating everywhere looks like the case those tools were built for. Which of them did the work on this sample was never isolated.&lt;/p&gt;

&lt;p&gt;Only Pillow's &lt;code&gt;optimize&lt;/code&gt; flag was used for PNG; no dedicated PNG optimizer was tried, so the table compares lossless WebP with one PNG encoder rather than with PNG as a format.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wiring it in without betting on a rule
&lt;/h2&gt;

&lt;p&gt;The approach I'd take is to stop picking a format up front and let each page prove it. Encode the page both ways, keep the smaller file, and log which one won. The snippet below is an illustrative sketch and not the script that produced the table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;io&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;BytesIO&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="no"&gt;PIL&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Image&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;pick_lossless&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page_img&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;bytes&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# sketch: try both lossless encoders, keep the smaller one&lt;/span&gt;
    &lt;span class="n"&gt;candidates&lt;/span&gt; &lt;span class="o"&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;for&lt;/span&gt; &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"optimize"&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="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"webp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"lossless"&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="s2"&gt;"method"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6&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;sink&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BytesIO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;page_img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sink&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upper&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="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;candidates&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sink&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getvalue&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="nb"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;candidates&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&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;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&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;Photo-heavy pages need their own branch to a lossy format, and colour count is one obvious signal for spotting them. The other check before switching is whether every place your images end up accepts WebP, from email templates to upload forms and older desktop software. This test says nothing about that.&lt;/p&gt;

&lt;p&gt;For one-off conversions outside a pipeline, ImgIng &lt;a href="https://imging.ai/" rel="noopener noreferrer"&gt;https://imging.ai/&lt;/a&gt; is one desktop-browser option. It renders at 144, 216 or 300 DPI with 216 as the default and exports PNG, JPEG or WebP. During this test's network capture, no request carrying the file went out while it processed. Which WebP mode its export uses was not checked, so none of its files are in the table above. Whatever tool does the converting, zoom in on the tiniest lettering once it's done and confirm the small letters still look like the PDF.&lt;/p&gt;

&lt;p&gt;To check this on your own documents, render one text page, one chart and one photo at the DPI you actually ship. Save each as PNG and as lossless WebP and compare the bytes, and the photo page will show you where the exception goes.&lt;/p&gt;

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