我的网站上有一些裁剪功能。
所以,问题在于真实的照片尺寸比裁剪区域大,当我试图获得这种裁剪动作的实际结果时,我得到可见的比例 - 在css区域调整大小而不是从边缘尺寸这个图像。如何计算从调整大小到实际大小的裁剪比例此图像。
我这样做但是它无法正常工作,我应该使用一些数学函数还是什么,有人能帮忙吗?
var width = img.width;
var height = img.height;
// c.x, c.y, c.w, c.h is cropping coords which i recive from crop plugin callback function
// 360 is modal window size, resized area for displaying img
function showCoords(c) {
cords_node = {
"x": c.x ,
"y": c.y,
"width": width < c.w ? c.w : (width / 360) * c.w,
"height": height < c.h ? c.w : (width / 360) * c.w
/*x2: c.x2,
y2: c.y2*/
};
return cords_node;
}
答案 0 :(得分:2)
找出变化的比例:
// find the ratio of change in H and W...
var ratioW = $('.image')[0].naturalWidth / $('.image').width();
var ratioH = $('.image')[0].naturalHeight / $('.image').height();
var ratio = Math.min(ratioW, ratioH);
// now.. multiply all your coords by 'ratio'
// ...