Skip to content

Instantly share code, notes, and snippets.

View rodrigopolo's full-sized avatar

Rodrigo Polo rodrigopolo

View GitHub Profile
@rodrigopolo
rodrigopolo / gist:62c21b25a23d34fee6a0
Created February 10, 2015 05:54
Calc image resize dimensions in JS
function calcResize(op){
var ratio = Math[(op.fill)?'max':'min'](op.to.width/op.from.width,op.to.height/op.from.height);
var r = {
width: Math.round(op.from.width * ratio),
height: Math.round(op.from.height * ratio)
}
r.x = Math.round((op.to.width - r.width) / 2);
r.y = Math.round((op.to.height - r.height) / 2);
return r;
}