Notes › Tech Notes › 270° Clamps to 180°, Not -90°: The Angle Clamp and Canvas Ledger

270° Clamps to 180°, Not -90°: The Angle Clamp and Canvas Ledger

On the rotate page the number box clamps 270 to 180 instead of -90, while four left-90 clicks wrap back to the original pixels. Measured in headless Chrome: rounding runs before clamping, a 240×160 PNG at 30° needs a 288×259 box and jumps from 1471 B to 11059 B, and 0° stays byte-identical only for PNG sources.

You Try to Spin Back to 270°, but the Page Pins You at 180°

The image was first rotated 90° counterclockwise, so you add a 270 in the angle number box to spin it back — intuitively 270° and -90° are the same pose. Instead the slider, the number box and the label all stop at 180 in lockstep, not -90. This page nails the angle to ±180: anything out of range sticks straight to the endpoint, -360 lands on -180, and both 1000 and "1e3" land on 180, with no modulo anywhere; if you want the -90 pose, type -90. Every figure below was click-measured with headless Chrome against the real template, on a self-made 240×160 solid-color PNG sample.

Two Inputs, Two Layers of Clamping

The two angle inputs stay in sync, but an out-of-range value goes through a different layer on each side. The slider side is folded by the browser first: write 270 and, with no event dispatched, the read-back is already "180"; -270 reads back "-180"; the decimal "91.7" is absorbed into "92" by the step. The number box side does not fold: write 270 and it still reads back "270" with rangeOverflow true, and only when the change event reaches setAngle does JS clamp it to 180 and write both boxes back. The number box also listens only for change: dispatch just an input event and the whole chain stays stuck at -45. In other words, the same typed value passes through two independent gates before it ever reaches the canvas, and each gate folds on its own schedule.

One out-of-range value, two paths, two folds Slider written 270 Browser folds first → 180 Number box written 270 JS clamps → 180 (not modulo -90) Click left 90, press 3 gives -270 Wraps → 90, not clamped

Figure 1: the number box clamps 270 into 180 while the button winds -270 back to 90 — two answers coexist.

Rounding Runs Before Clamping, and a 0.5 Degree Can Resize the Product

setAngle rounds first and only then clamps into ±180, and the order cannot be swapped. Both 45.6 and 45.5 land on 46, and 44.5 lands on 45; 180.5 is rounded to 181 and then clamped back to 180. The giveaway is -179.5: round carries toward positive infinity and yields -179 instead of -180, and the canvas changes from the 180° 240×160 to 243×164 accordingly — the carry direction of a half degree directly changes the exported size. The empty string, "abc", pure spaces and "45deg" all land on 0; among them, values carrying a unit or spaces are already an empty string at the number-box read-back stage and never reach the JS layer.

The Step Buttons Wrap Around, They Do Not Clamp

Clicking "Turn Left 90°" four times measures the chain 0→-90→-180→90→0: the third press computes -270, which while (v < -180) v += 360 folds back to 90. The canvas alternates long and short edges, the first and last hashes are both 65c409c5, and four presses return the original pixels. Controls: right ×4 gives 0→90→180→-90→0; rotate 180° ×3 gives 0→180→0→180; starting from 170 and pressing right 90, 180, 180 gives 170→-100→80→-100; from -180, one more left-90 press jumps straight to 90.

Bounding Box: Every Degree Adds a Surcharge to the Canvas

With "Enlarge canvas to fit the whole image" checked by default, width = round(orig width×|cosθ|+orig height×|sinθ|), and the height is symmetric. The 240×160 sample was measured over 14 steps, and the formula matches the canvas step by step:

AngleCanvasPixelsNote
0°240×16038400original size
30°288×25974592nearly double
45°283×283800891.09× more
90°160×24038400exact swap
135°283×28380089same value as 45°
179°243×164—pays 1452 extra pixel slots over 180°

The shared value at 45° and 135° comes from the symmetry of |cos|+|sin|, and -30 and 30 are likewise both 288×259. Switching to a 120×80 control, 30° gives 144×129 and 45° gives 141×141; extrapolating, 1920×1080 @30° needs 2203×1895 and @45° needs 2121×2121. Unchecking the box keeps the canvas at the original size, and the four overflowing corners are clipped.

Flip Is a State Switch, Not a Command

Clicking horizontal flip first and then entering 30, versus entering 30 first and then flipping, leaves the canvas hash at 288x259:81af2666:298368 either way — the button toggles a boolean, and the final matrix is always rotate followed by scale, so the order is irrelevant — the sequence of clicks changes the path you take, never the bytes you export. flipH plus flipV parked at 0° and angle=180 share the canvas 240x160:aa4309c5 with a pixel difference of 0; but +30° with flip (81af2666) and -30° with flip (4c1e1859) are not equivalent. Direction semantics: after +90°, the red block declared as pixels [200,30,40] lands at (100,40), confirming that positive values mean clockwise in screen coordinates.

Byte Ledger: 0° Identity Only Holds for PNG Sources

A PNG source of 1471 B, exported at 0° with keep and a transparent base, still comes out at 1471 B — the first 12 SHA characters match and the file is byte-for-byte identical, with zero difference across the 38400 decoded pixels of canvas and product. The same image as a JPEG source of 1380 B exports 1205 B at 0° with 2060 pixels changed, mean 0.824 and max 78 — the quality 0.92 is hard-coded in the source, the interface has no control for it, and standing at 0° still re-encodes. Size over angle is non-linear too: 0° 1471→30° 11059 (7.5× the original)→45° 6098→90° 1747 B. 45° has more pixels yet comes out smaller; 90° has the same pixel count as the original, but 1747 exceeds 1471 — row order and filtering changed, so the size ledger is zero while the byte ledger is not. On the same 283×283 canvas in three formats: PNG 6098, JPG 8493, WebP 4670 B.

PNG source 1471 B: angle and product bytes on one axis 0° 240×160 · 1471 B 30° 288×259 · 11059 B 45° 283×283 · 6098 B 90° 160×240 · 1747 B

Figure 2: 45°, with more pixels, comes out half the size of 30° — bytes are not monotonic in size.

Output Formats and Failure States

"Keep original format" only honors a real JPEG: a webp source of 594 B @0° with keep exports a 1471 B PNG whose sha matches the PNG source export; a bmp source of 28854 B exports a 581 B PNG; GIF can enter the editor but comes out as PNG, and the format dropdown has no GIF tier either — "GIF supported" really means in-but-not-out, and the per-frame ledger belongs to the image-splitting article. Failure states, verbatim: downloading with no image selected reports "select an image first"; text/plain and a true PNG with an empty type string are both blocked with "please choose an image file"; a fake png reports "cannot read this image". After a failure, entering 45 syncs the controls, but the info line stays at 240×160 · 0° — render returns early without raising an error. Swapping images runs resetAll and clears to zero; parameters never carry across images.

Cross References

This article only measures the angle and size ledger of the image rotate page; how photo orientation tags divide their work with a real pixel rotation is covered in a dedicated article and not repeated here; if the goal is just shrinking JPEG size, the ledger of a hard-coded 0.92 re-encode points you to the image compress page, where quality has a slider you can drag.

Q: Why does entering 270 not land on -90?

Clamping is not modulo. setAngle rounds first and then clamps into ±180: 270 sticks to the upper endpoint 180, and -360 sticks to -180. If you want the -90° pose, type -90 directly; the button path that winds -270 back to 90 is not on this chain.

Q: If the angle stays at 0, is the file lossless?

Depends on the source format. A 1471 B PNG source goes in and out with identical bytes; a 1380 B JPEG source still exports 1205 B, with 2060 pixels altered by the hard-coded 0.92 quality. 0° is geometric identity, not byte identity.

Q: How large does the canvas get at 45°?

240×160 becomes 283×283, with pixels rising from 38400 to 80089; extrapolating, 1920×1080 @45° needs 2121×2121. The only way to lock the size is to uncheck the canvas enlargement, at the cost of the four corners being clipped.

📎 Related articles

JSON to YAML Reorders Keys and Quotes Numbers: Output Side and 4 Indent Tiers 2026-11-29 Charset Pool and Exclusions on the Random Password Page, Measured 2026-11-29 The PNG Quality Slider Spins for Nothing at Every Byte Size 2026-11-29 Text Set Operations Measured: Duplicates and Order 2026-11-28 HTML Beautify Deletes the Blank Line Inside pre 2026-11-28