You can try this:
var canvas = $(img_selector).cropper('getCroppedCanvas'); //pega o canvas
var data = canvas.toDataURL('image/jpeg'); //gera a base64 com o mimetype
var base64 = data.split(',').reverse()[0]; //pega somente o código
sessionStorage.setItem("base64", base64); //salva na storage
You can call this piece of code at a few specific times:
When the crop is finished:
$(img_selector).on('cropend.cropper', function (e) {
var $cropper = $(e.target);
var canvas = $cropper.cropper('getCroppedCanvas');
[...]
// cole o resto do código aqui
});
When the cropbox is changing:
$(img_selector).on('cropmove.cropper', function (e) {
var $cropper = $(e.target);
var canvas = $cropper.cropper('getCroppedCanvas');
[...]
// cole o resto do código aqui
});
Other plugin events can be found here .