Notes › Life Essays › Padding accounting in long-image concat: left and right stay 0 at 100px, canvas dual thresholds 32767 and 268435456

Padding accounting in long-image concat: left and right stay 0 at 100px, canvas dual thresholds 32767 and 268435456

Measured on three vertically stitched screenshots: at padding 100 the canvas width stays 800 and the centered row offset remains 0; of the two gates, edge 32767 and area 268435456, the area gate fires first, and past it the canvas silently becomes blank.

Measuring the surrounding padding row on its own

The trigger was stitching three screenshots into one long image vertically and, while at it, dragging the surrounding padding slider to 100. This single-file stitcher weighs 12326 bytes across 294 lines, exposes 13 ic* functions, and carries zero external dependencies. The formulas are very short: for the vertical layout W=maxW and H=margin*2+gap*(n-1)+Σh, and margin only ever shows up on the second line. Samples 800×500, 600×900, 400×300 under the default gap=8 and margin=0 compose into 800×1716; drag padding to 100 and the canvas becomes 800×1916, without gaining a single pixel of width. The arithmetic never promised them any width, and the interface never says it does.

Point sampling settles it: with margin=100 active, the upper-left corner of the widest image, (10,150), reads 255,0,0,255, which is image body, not blank space. The centered row computes dx=round((W-margin*2-dw)/2)+margin; substituting the widest image gives round((800-200-800)/2)+100=0. So even with the slider pushed to its end stop, the left and right margins of the widest image are still 0.

Per-image landing points of the three alignment rows

Alignment rowLanding pointsCanvasMeasured
Centered paddingdx=0 / 100 / 200800×1716with margin=100 the dx line does not change one character
Left (top) aligndx=margin800×1756the widest image's right edge reaches 820, the last column is residue
Scale to uniform widthdx all 0800×2316dh=500 / 1200 / 600 stay proportional

The third option's label reads, verbatim, "scale to a uniform width (height proportional)". It is a choice, not an automatic behavior, and the default stops on the centered row; the marketing sentence about width auto-alignment does not match what the interface actually offers.

Vertical: margin only enters the H line padding 0canvas 800×1716 padding 100canvas 800×1916 dx still 0 / 100 / 200widest image left margin 0 H=margin*2+gap*(n-1)+Σh: padding only lives on this line
Figure 1: padding 0 versus padding 100, the canvas ledger differs only in height

The start row: padding was not gained, a real crop was

Switching to left (top) align sets dx=margin, so the widest image's right edge pushes out to 820, and the 20 columns beyond the canvas width 800 are simply cut away by drawImage. Sampling column 799 at (799,300) still reads 255,0,0,255, which is the leftover sliver rather than empty space. Flipping the reasoning to the horizontal direction, the tallest image's bottom=920 crosses H=900 and is cropped the same way.

Over-length protection: 32767 and 268435456 are two independent gates

Two conditions decide it: either a single edge exceeding 32767, or the area crossing 268435456, which is exactly the square of 16384, and the comparison does not include equality. Who arrives first can be computed: 268435456/32767=8192.25, so once the width passes 8192 the area gate rings first. That makes 32767×8192, area 268427264, pass while 32767×8193, area 268460031, triggers the warning. The warning text, verbatim, says the concat result is about 33000×1226px, beyond the browser canvas safety range, and may fail to stitch; it suggests reducing the image count or splitting into several segments and stitching each on its own. Immediately after, canvas.width returns to 0, height keeps the stale 1716, the info line resets to a dash, and the base fill plus the whole drawing pass are skipped.

The local Chrome 157.0.8103.80 was probed one level at a time for the real ceiling: 16384×16384, 32767×8192 and 65535×64 can be drawn, while 65536×1 fails without throwing any exception. Cross the area threshold and what you hold is a dead canvas: every pixel reads zero and toDataURL only returns 'data:,'. The code's area threshold equals the measured ceiling, whereas the single-edge 32767 is a conservative reading; what the warning intercepts is precisely this kind of silent failure. The on-page tip about height exceeding 20,000 pixels fires even earlier than the code threshold does.

The two gates and where the real ceiling sits 32767×8192268427264 passes 32767×8193268460031 triggers dead canvas: all pixels 0toDataURL returns data:, Measured ceiling: area 268435456, single edge to 65535
Figure 2: the area gate rings before the single-edge gate, and past it lies a dead canvas

Transparent base with JPG: near-black, but not pure black

When transparent is selected, the code skips fillRect altogether. Switch the output format to JPG and the transparent region, after encode then decode, lands at (2,0,2) with alpha becoming 255. That is a near-black carrying a two-step chroma offset, neither pure black nor the white base you might expect; the very same canvas exported as WebP keeps (0,0,0,0) intact. Even the pure red 255,0,0 comes back as 254,0,0, because lossy compression takes a bite out of the whole frame. The standing tip to use PNG or WebP for transparent backgrounds relies purely on the reader's self-discipline: when JPG and a transparent base meet, the code does not intervene at all. The quality slider defaults to 92, and download feeds 92/100=0.92 into toDataURL. On the PNG row the slider control is merely hidden while 0.92 is still passed in, and the measured PNG dataURLs produced with q0.5 and q0.92 are byte-identical, the same 45058-character string both times.

The size ledger has to state the sample shape first

  • An 800×800 noise sample built from 400 random 20×20 color blocks yields these dataURL string lengths: jpg0.5=66915, jpg0.92=135095, png=32270. For flat color-block images PNG actually comes out ahead, so the claim that JPG is smaller holds only under conditions.
  • The same 800×1716 image on a transparent base: jpeg0.92 runs 21075 characters while webp0.92 takes only 5219.
  • The upload note says the tool supports PNG / JPG / WebP / BMP / GIF, but the output only offers three rows; BMP can enter the pipeline and never leaves it.

Clearing the stage and the first frame: two behaviors worth knowing

Clearing everything empties the list but not the canvas. Measured: after the clear, canvas is still 800×1716 while the list is already empty, and clicking download hands you a download started message plus a png named concat- followed by a timestamp; its href runs 45058 characters long, exactly the old composite's string, because the guard checks canvas.width rather than the image count. If every uploaded image fails to decode you likewise land in an empty editor that says there are no images yet while the canvas quietly keeps its old content. The thumbnails reference blob URLs that have already been revoked, so each rebuild of the list can show broken thumbnails; the main canvas itself is not affected.

GIF goes through new Image(): a hand-built 2190-byte, two-frame GIF, a 30×20 red block plus a 30×20 blue block, decodes to naturalWidth/Height=30×20, draws the first-frame color (255,0,0), and the size ledger feeds H from that box. Sampling the second frame was not measured in an environment that does not drive the animation. This vertical long-image stitcher retiles the entire canvas for every slider notch; for animated pictures, first split them into single frames with GIF to image sequence and then pick and stitch, and the per-frame reading has its own article on animated frame extraction practice.

Quick questions and answers

Q: padding dragged to 100, why is there still no left or right margin on the long image?

The vertical canvas width always equals the widest image, and margin is only added into the height; on the centered row the widest image's dx is permanently 0. If you truly want a ring of margin, either pad every image wider before stitching or move the whole layout to the horizontal row.

Q: switched to left align, why is a strip cut off the right side?

That row uses dx=margin, so the widest image's right edge pushes out to 820 beyond the canvas's 800, and the extra columns are cropped away by drawImage; column 799 is exactly that residue. Stop back on the centered row and nothing is cropped, but no left or right padding is produced either.

Q: stitching suddenly fails with only one line of warning?

After crossing the single edge 32767 or the area 268435456, the canvas width returns to 0 and the info line shows a dash, and clicking download only tells you to add images first. Reducing the count or splitting into two segments are the two routes written into the tip itself; approaching the threshold without crossing it earns you no advance warning whatsoever.

Q: does a transparent base saved as JPG come out pure black?

Measured, it lands at (2,0,2) with alpha 255, a near-black rather than pure black; among the tested formats only PNG and WebP preserve (0,0,0,0). Compression artifacts were not measured this round, so no conclusion is drawn about them.

📎 Related articles

Weigh the color distance before swapping the background: at tolerance 52 the red shift replaces 0.7296, the green shift only 0.2458 2026-11-21 43 segment paces sum to 16 seconds past 3:30:00: each field on the page rounds by a different rule 2026-11-14 Both Formulas Show Up, Only One Enters TDEE: parseInt Truncation, Two Rounding Rules and Three Hard-Coded Tiers on the 221-Line BMR Page 2026-11-12 Upper-Casing .ß Adds One Slot to the Whole Line: Three Tiers Measured Line by Line on an 18-Line Sample 2026-11-09 Which three of the four switches default to on: collapse rules, first-seen representatives and the dedupe short circuit 2026-11-08