My programs used to very awkwardly try to scale an image... I would try to fit it on the x-axis, then the y-axis, or else the y-axis then the x-axis, depending on the original dimensions, and also it would probably need rescaling after that scaling phase...
No more! Now I get how to scale it easily in one phase. (It seems so obvious now!)
Basically, we make sure it fits on x-axis. Then, with the updated scaling dimension, we check whether it needs further scaling on the y-axis.
The check on the x-axis is with the original width, while the check on the y-axis is with the scaled height (from scaling the x-axis to match the desired width).
When the scale is set, it is always calculated with the original width/height.
JsFiddle:
Monday, February 6, 2023
Easily scale rect to fit dimensions
Subscribe to:
Post Comments (Atom)
Coding Challenge #54 C++ int to std::string (no stringstream or to_string())
Gets a string from an integer (ejemplo gratis: 123 -> "123") Wanted to come up with my own function for this like 10 years ago ...
-
I NEEDS MY JAVASCRIPT PLEASE :) Open txtcode .txt Save as .gct Please click the blue cheat code title to activate it, a...
-
Naruto Personality Quiz Please enable javascript ☯ Which Naruto Character Are You?
-
// Daily Coding Challenge #34 // make a (made up) pallindrome from a word using as few characters as possible // Example: race -> ecarac...
No comments:
Post a Comment