You can try it this way:
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 specific times:
When 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.
More I have no idea where to add this excerpt...
– Jean Carlos Ferreira Lemes
When you want to do it?
– João Paulo
When to cut the image
– Jean Carlos Ferreira Lemes
Check the edition.
– João Paulo
I put it like this:
– Jean Carlos Ferreira Lemes
'cropend.Cropper': Function(e) { var canvas = $(). Cropper('getCroppedCanvas'); //grabs the canvas var data = canvas.toDataURL('image/jpeg'); //generates Base64 with mimetype var Base64 = data.split(','). Reverse()[0]; //takes only the code Alert(Base64); //shows in Storage }
– Jean Carlos Ferreira Lemes
more in google Chrome shows Uncaught error Typeerror: canvas.toDataURL is not a Function
– Jean Carlos Ferreira Lemes
Guys I already solved the problem. kkkk ...
– Jean Carlos Ferreira Lemes
to clarify, I put more detailed the codes within the events.
– João Paulo