[英]cropped image height and width not getting fixed as 160px
I have created an application using cropper.js for cropping an images. 我使用cropper.js创建了一个用于裁剪图像的应用程序。 The application is working and the image is cropping 该应用程序正在运行,图像正在裁剪
I have given a fixed image width and height for the cropped image as 160 option like as given below. 我为裁剪后的图像提供了固定的图像宽度和高度,作为160选项,如下所示。
$("#getCropped").click(function () {
$('#croppedImage').html($image.cropper('getCroppedCanvas', {
width: 160,
height: 160
}));
});
But the issue is that when I select an area as width and height somewhat equal as the cropped Image, then I am getting the cropped Image height ans width as 160px like as shown below 但是问题是,当我选择一个区域作为宽度和高度与裁剪后的图像相等时,然后将裁剪后的图像高度和宽度设为160px,如下所示
but when I select an area where width and height varies in which height is more than width as the cropped Image, then I am not getting cropped Image as height and width as 160px like as shown below 但是当我选择一个宽度和高度变化的区域,其中高度大于宽度作为裁剪图像时,那么我不会像以下所示那样将裁剪图像的高度和宽度设为160px
Can anyone please tell me some solution for this 谁能告诉我一些解决方案
i got the answer after several tweaks, this is my solution and it works, i was trying to set the width to 240px and the height to 507px, upon initialization. 经过几次调整后,我得到了答案,这是我的解决方案,它可以正常工作,我尝试在初始化时将宽度设置为240px,将高度设置为507px。
var cropper;
var imgx;
$(function(){
var imgx = $('#cpdiv').find('img');
cropper = new Cropper(imgx[0], {
autoCropArea: 0,
strict: false,
guides: false,
highlight: true,
dragCrop: false,
//cropBoxMovable: false,
cropBoxResizable: false,
data:{
width: 160,
height: 160,
},
crop(event) {
console.log(event.detail.width);
console.log(event.detail.height);
},
});
});
and this worked for me perfectly for me... when you console.log the dimensions it all reflects the exact dimensions as the cropped section. 这对我来说非常适合...当您console.log记录尺寸时,所有尺寸都反映了裁剪部分的确切尺寸。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.