Make crop editor usable #22
@ -292,10 +292,23 @@ class CropEditor {
|
|||||||
let targetAspectRatio = current.crop_width / current.crop_height;
|
let targetAspectRatio = current.crop_width / current.crop_height;
|
||||||
|
|
||||||
if (Math.abs(currentAspectRatio - targetAspectRatio) > 0.001) {
|
if (Math.abs(currentAspectRatio - targetAspectRatio) > 0.001) {
|
||||||
|
// Landscape?
|
||||||
if (targetAspectRatio > 1.0) {
|
if (targetAspectRatio > 1.0) {
|
||||||
this.crop_height.value = Math.ceil(this.crop_width.value / targetAspectRatio);
|
let height = Math.ceil(this.crop_width.value / targetAspectRatio);
|
||||||
} else {
|
if (parseInt(this.source_y.value) + height > this.original_image.naturalHeight) {
|
||||||
this.crop_width.value = Math.ceil(this.crop_height.value * targetAspectRatio);
|
height = this.original_image.naturalHeight - this.source_y.value;
|
||||||
|
}
|
||||||
|
this.crop_width.value = height * targetAspectRatio;
|
||||||
|
this.crop_height.value = height;
|
||||||
|
}
|
||||||
|
// Portrait?
|
||||||
|
else {
|
||||||
|
let width = Math.ceil(this.crop_height.value * targetAspectRatio);
|
||||||
|
if (parseInt(this.source_x.value) + width > this.original_image.naturalWidth) {
|
||||||
|
width = this.original_image.naturalWidth - this.source_x.value;
|
||||||
|
}
|
||||||
|
this.crop_width.value = width;
|
||||||
|
this.crop_height.value = width / targetAspectRatio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user