Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get cropped image from cropper js?

I am trying to get cropped image result from cropperjs but I dont know how to get it. I tried to search online but couldn't find a solution.

My code is as given below.

$(function () 
  {


  $image=null;

  var img = document.createElement("IMG");
  img.src = "";
  img.setAttribute('id', "showImage");
  document.getElementById("img-container").appendChild(img);

  var url = canvas.toDataURL();
  canvasImage.src = url;
  console.log(canvasImage);

  document.getElementById("showImage").src=canvasImage.src;
  $image = $('#showImage');
  $image.cropper({
    movable: true,
    zoomable: false,
    rotatable: false,
    scalable: false
  });

  $('#replace').on('click', function () {   
    var croppedimage = new Image();
    var cropBoxData = $image.cropper('getCropBoxData');
    croppedimage=$image.data('cropper');
    // croppedimage= this.cropper.
    console.log($image);
  });
});
like image 206
Syed Ali Muqaddas Naqvi Avatar asked Mar 09 '23 02:03

Syed Ali Muqaddas Naqvi


1 Answers

$('#replace').on('click', function () {   
    var croppedimage = $image.getCroppedCanvas().toDataURL("image/png");
    console.log(croppedimage);
});

you can get base64

like image 156
Jeeva Avatar answered Mar 23 '23 00:03

Jeeva