我正在使用来自Fengyuanchen的很棒的jquery cropper插件。
我有一个问题,当某些图片上传时,它会旋转,而不是在右侧,我必须让用户旋转它们。我会通过上传图片
ajax
. 我得到了错误
rotate is not defined
我被困了几个小时。
$('#profilePhoto').on( 'change', function(){
if (this.files && this.files[0]) {
if ( this.files[0].type.match(/^image\//) ) {
var reader = new FileReader();
reader.onload = function(evt) {
var img = new Image();
img.onload = function() {
$("#profileImageContainer").hide();
$("#rotateImg").show();
context.canvas.height = img.height;
context.canvas.width = img.width;
context.drawImage(img, 0, 0);
cropper = canvas.cropper({
aspectRatio: 1 / 1,
rotatable: true,
});
$('#btnCrop').click(function() {
// Get a string base 64 data url
var croppedImageDataURL = canvas.cropper('getCroppedCanvas').toDataURL("image/png");
});
$('#rotateImg').click(function () {
cropper.cropper.rotate(90);
});
};
img.src = evt.target.result;
};
reader.readAsDataURL(this.files[0]);
}
else {
alert("Invalid file type! Please select an image file.");
}
}
else {
alert('No file(s) selected.');
}
});
这里的主要问题是范围,因为它看起来不像是重新调整裁剪器变量。
这个问题会出现,因为当用户上传照片时,有时照片会自动旋转。如果我可以先解决这个问题,而不必让用户旋转图像会更好