Menu

What 0, -5, 12.75 and 1e3 actually do to an image tool's width field
πŸ“°

What 0, -5, 12.75 and 1e3 actually do to an image tool's width field

DEV Community: frontendΒ·sharefun2023Β·28 days ago
#oKqGra9A
#devtofrontend#devto#dev#value#number
Long article (1106 words) β€” no AI summary yet.
Reading 0:00
15s threshold

What 0 , -5 , 12.75 and 1e3 actually do to an image tool's width field

I maintain a handful of free, client-side image tools. Last month I ran an audit across all of them and found that the numeric size fields β€” the "width / height" boxes almost every canvas-based tool has β€” fail in four different ways depending on what you type into them.

Not one of those failures shows up if you only test the happy path, because the happy path is "leave the box empty".

Every number below was measured in Chromium 149 on Linux, against my own pages. I'll show the exact mechanics, then the six-line fix.

The four kinds of damage

Take a resizer that reads the box like this β€” which is what most tutorials show:

const w = box . value ? parseInt ( box . value ) : naturalWidth ; canvas .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.