I am trying to implement cropped image upload system using JQuery cropper plugin But i am struggled with cropped image section
The issue is
size of the cropped image is larger than the actual cropped size
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);
}
})
})