SHARE
TWEET

scaleToFit

ulfben Feb 13th, 2016 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function scaleToFit(srcWidth, srcHeight, maxWidth, maxHeight) {
  2.     var ratio = Math.min(maxWidth/srcWidth, maxHeight/srcHeight);
  3.     return {width:srcWidth*ratio, height:srcHeight*ratio};
  4. }
RAW Paste Data
Want to get better at JavaScript?
Learn to code JavaScript in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top