diff --git a/public/js/crop_editor.js b/public/js/crop_editor.js index e603210b..ddfab114 100644 --- a/public/js/crop_editor.js +++ b/public/js/crop_editor.js @@ -255,14 +255,17 @@ class CropEditor { let scaleFactor = this.getScaleFactor(); - this.source_x.value = parseInt(this.source_x.value) + Math.ceil((this.dragEndX - this.dragStartX) * scaleFactor); - this.source_y.value = parseInt(this.source_y.value) + Math.ceil((this.dragEndY - this.dragStartY) * scaleFactor); + let x = parseInt(this.source_x.value) + Math.ceil((this.dragEndX - this.dragStartX) * scaleFactor); + if (x + parseInt(this.crop_width.value) > this.original_image.naturalWidth) { + x += this.original_image.naturalWidth - (x + parseInt(this.crop_width.value)); + } + this.source_x.value = Math.max(x, 0); - // let width = Math.ceil(Math.abs(this.dragEndX - this.dragStartX) * scaleFactor); - // this.crop_width.value = Math.min(width, this.original_image.naturalWidth - this.source_x.value); - - // let height = Math.ceil(Math.abs(this.dragEndY - this.dragStartY) * scaleFactor); - // this.crop_height.value = Math.min(height, this.original_image.naturalHeight - this.source_y.value); + let y = parseInt(this.source_y.value) + Math.ceil((this.dragEndY - this.dragStartY) * scaleFactor); + if (y + parseInt(this.crop_height.value) > this.original_image.naturalHeight) { + y += this.original_image.naturalHeight - (y + parseInt(this.crop_height.value)); + } + this.source_y.value = Math.max(y, 0); this.positionBoundary(); }