zhanziyang / vue-croppa

A simple straightforward customizable mobile-friendly image cropper for Vue 2.0.
https://zhanziyang.github.io/vue-croppa/
ISC License
967 stars 128 forks source link

Crop the aspect ratio #225

Closed koki000 closed 4 years ago

koki000 commented 4 years ago

Is there an option to keep the original size (for example original width) of the picture and just crop the aspect ratio no matter the size of the container? If I upload a picture with dimensions 1200x700px I would like to crop the image to fit the aspect ratio of 16:9 and get 1200x675px. Is this possible?

koki000 commented 4 years ago

I've managed to do it by checking the "naturalWidth" on resize and after upload and updating the "quality" based on the width of the container.

Sample for resize event:

if(this.myCroppa.naturalWidth > 0){
   if(picWrapper.getBoundingClientRect().width < this.myCroppa.naturalWidth)
   this.picQuality = this.myCroppa.naturalWidth / picWrapper.getBoundingClientRect().width;
}