Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set crop box to full width and full height of the container preview(Cropper js)

Tags:

javascript

How to make cropper js cropBox equal to container size. In other words the cropbox area should be equal to the available area of the preview height and width.

like image 591
chalo Avatar asked Feb 21 '17 20:02

chalo


2 Answers

A better solution maybe setting autoCropArea as 1

{ autoCropArea: 1}
like image 90
Hüseyin Dursun Avatar answered Nov 04 '22 19:11

Hüseyin Dursun


I found the solution a while ago, and I just realized that I had not answered this question.

The way I managed to set the full width was:

var image = document.getElementById('image');
var cropper = new Cropper(image, {
  aspectRatio: 16 / 9,
  crop: function(e) {
    console.log(e.detail.width);
    console.log(e.detail.height);

  }
});

var contData = cropper.getContainerData(); //Get container data
cropper.setCropBoxData({ height: contData.height, width: contData.width  }) //set data
like image 4
chalo Avatar answered Nov 04 '22 18:11

chalo