【发布时间】:2017-01-17 06:47:40
【问题描述】:
我正在尝试使用JQuery cropper plugin 实现裁剪图像上传系统,但我在裁剪图像部分遇到困难
问题是
裁剪后的图片尺寸大于实际裁剪后的尺寸
HTML
//load the image for crop
<div class="img-container">
<img id="image" src="latest.jpg">
</div>
//load the cropped image after cropping
<img id="db-image" />
<input type="button" name="" id="getimage" value="getimage"/>
Javascript
//init the cropper plugin
$('#image').cropper({
aspectRatio: 16 / 9,
crop: function(e) {
},
built: function() {
}
});
//load the cropped image into img when click on the button
$('#getimage').click(function(){
//get the cropped image as blob
$('#image').cropper('getCroppedCanvas').toBlob(function(blob){
console.log(blob);
//convert blob to base64 string
var reader = new window.FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
base64data = reader.result;
//display cropped image
$('#db-image').attr('src',base64data);
}
})
})
【问题讨论】:
标签: javascript php jquery