我正在使用来自丰源镇的jquery插件。
我有一个问题,当某些图片上传时,它会旋转,而不是在右边,我必须让用户旋转它们。我将通过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.');
}
});这里的主要问题是作用域,因为它看起来不需要重新配置cropper变量。
这个问题的出现是因为当用户上传照片时,这张照片会自动旋转。如果我能先解决这个问题,而不用让用户旋转图像会更好。
发布于 2018-05-19 18:57:02
真是愚蠢的错误。而不是:
cropper.cropper().rotate(90);我应该申请:
cropper.cropper('rotate', 90);https://stackoverflow.com/questions/50428105
复制相似问题