如何将图片进行精确的Crop Image操作?
- 内容介绍
- 文章标签
- 相关推荐
本文共计105个文字,预计阅读时间需要1分钟。
pythondef crop(cropW, cropH, w, h): k1=cropW / w k2=cropH / h k=k1 + k2 if k1 > k2 else k2 fitW=math.ceil(w * k)
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); 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 + ')'); }
本文共计105个文字,预计阅读时间需要1分钟。
pythondef crop(cropW, cropH, w, h): k1=cropW / w k2=cropH / h k=k1 + k2 if k1 > k2 else k2 fitW=math.ceil(w * k)
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); 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 + ')'); }

