Advertisement
rodrigopolo

Image Resize

Feb 8th, 2015
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calcResize(op){
  2.     var ratio = Math[(op.fill)?'max':'min'](op.to.width/op.from.width,op.to.height/op.from.height);
  3.     var r = {
  4.         width: Math.round(op.from.width * ratio),
  5.         height: Math.round(op.from.height * ratio)
  6.     }
  7.     r.x = Math.round((op.to.width - r.width) / 2);
  8.     r.y = Math.round((op.to.height - r.height) / 2);
  9.     return r;
  10. }
  11.  
  12. console.log(calcResize({
  13.     from: {
  14.         width: 240,
  15.         height: 320
  16.     },
  17.     to: {
  18.         width: 320,
  19.         height: 240
  20.     },
  21.     fill: true
  22. }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement