jQuery imgAreaSelect
我有 3 个不同的 div,其中包含图像。每个 div 具有不同的宽度和高度。 我对它们都使用 jQuery imgAreaSelect。裁剪效果很好。 我的问题是我希望裁剪窗口打开时从初始裁剪开始。 我希望初始裁剪是给定纵横比的最大可能比例。
我正在使用的代码是:
var aspectratio1 = $('#cutout_'+cutout_id).height() / $('#cutout_'+cutout_id).width();
aspectratio = "1:" + aspectratio1;
var image_width = $('#CutoutImage').width();
var image_height = $('#CutoutImage').height();
var aspect = 1 / aspectratio1 ;
var NewWidth = Math.round(image_height * aspect);
var left = ((image_width - NewWidth) / 2);
var right = Math.round(NewWidth + left);
var x1 = left;
var y1 = 0;
var x2 = right;
var y2 = image_height;
$('#CutoutImage').imgAreaSelect({
aspectRatio: aspectratio,
instance: true,
zIndex: 9999,
x1: x1,
y1: y1,
x2: x2,
y2: y2
});
这似乎无法正常工作。非常感谢任何帮助或见解。
非常感谢
I have 3 different divs with images in them. Each div with a different width and height.
I am using jQuery imgAreaSelect on them all. Cropping works fine.
My problem is i would like when the cropping window opens to start with an initial crop.
I would like this initial crop to be the biggest possible porportions for the given aspect ratio.
The code I am working with is:
var aspectratio1 = $('#cutout_'+cutout_id).height() / $('#cutout_'+cutout_id).width();
aspectratio = "1:" + aspectratio1;
var image_width = $('#CutoutImage').width();
var image_height = $('#CutoutImage').height();
var aspect = 1 / aspectratio1 ;
var NewWidth = Math.round(image_height * aspect);
var left = ((image_width - NewWidth) / 2);
var right = Math.round(NewWidth + left);
var x1 = left;
var y1 = 0;
var x2 = right;
var y2 = image_height;
$('#CutoutImage').imgAreaSelect({
aspectRatio: aspectratio,
instance: true,
zIndex: 9999,
x1: x1,
y1: y1,
x2: x2,
y2: y2
});
This seems to not be working properly. Any help or insight is much appreciated.
Thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是完整的代码。它对我有用:
This is the complete code. It works for me:
嗯,这对我很有用
}
var x2 = x1 +cropwidth ;
var y2 = y1 + 作物高度;
Well this works good for me
}
var x2 = x1 + cropwidth ;
var y2 = y1 + cropheight;