Govind Samrow Govind Samrow - 4 months ago 54
jQuery Question

how to assign Croppie returned result to IMG?

I've using Croppie jQuery plugin for crop a image And returns a the cropped image encoded in base64.

My Code as below:

$uploadCrop.croppie('result', {
type: 'canvas',
size: 'viewport'
}).then(function (resp) {
var blobBin = atob(resp.split(',')[1]);
var array = [];
for (var i = 0; i < blobBin.length; i++) {
array.push(blobBin.charCodeAt(i));
}
var file = new Blob([new Uint8Array(array)], {type: 'image/png'});
//How to assign this to image
});


Please help me.

Answer

Assign directly to img because returns a the cropped image encoded in base64

http://foliotek.github.io/Croppie/

$uploadCrop.croppie('result', {
    type: 'canvas',
    size: 'viewport'
}).then(function (resp) {
    $('#img_elem_id').attr('src', resp);
});
Comments