gistfile1.txt /** * cropW, cropH: width and height to be cropped * w, h: width and height of source image */function crop(cropW, cropH, w, h) { let k1 = cropW / w; let k2 = cropH / h; let k = k1 k2 ? k1 : k2; let fitW = Math.ceil(w * k); le
/**
* cropW, cropH: width and height to be cropped
* w, h: width and height of source image
*/
function crop(cropW, cropH, w, h) {
let k1 = cropW / w;
let k2 = cropH / h;
let k = k1 > k2 ? k1 : k2;
let fitW = Math.ceil(w * k);
let fitH = Math.ceil(h * k);
let topLeftX = Math.ceil((fitW - cropW) / 2);
let topLeftY = Math.ceil((fitH - cropH) / 2);
console.info('fit wxh:' + fitW + 'x' + fitH + ' crop from (' + topLeftX + ',' + topLeftY + ')');
}
