Skip to content

Commit

Permalink
Adapt limit_minimum_cropping_size to work with current cropperjs vers…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
maethu committed Oct 17, 2023
1 parent d47d5f5 commit 7d27f30
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 16 deletions.
2 changes: 2 additions & 0 deletions news/150.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix minimal crop size implementation, to support current cropperjs version.
[maethu]
28 changes: 19 additions & 9 deletions resources/js/cropperpattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,35 @@ export default Base.extend({
limit_minimum_cropping_size: function () {
var current = this.cropper,
newbox = {};
const relativeWidth =
(current.canvasData.width /
current.canvasData.naturalWidth) *
this.options.target_width;
const relativeHeight =
(current.canvasData.height /
current.canvasData.naturalHeight) *
this.options.target_height;

if (
current.width < this.options.target_width ||
current.height < this.options.target_height
current.cropBoxData.width <= Math.round(relativeWidth) ||
current.cropBoxData.height <= Math.round(relativeHeight)
) {
newbox.width = this.options.target_width;
newbox.height = this.options.target_height;
if (current.x + this.options.target_width > this.options.true_width) {
const data = current.getData()
if (data.x + this.options.target_width > this.options.true_width) {
newbox.x = this.options.true_width - this.options.target_width;
} else {
newbox.x = current.x;
newbox.x = data.x;
}
if (current.y + this.options.target_height > this.options.true_height) {
if (data.y + this.options.target_height > this.options.true_height) {
newbox.y = this.options.true_height - this.options.target_height;
} else {
newbox.y = current.y;
newbox.y = data.y;
}
newbox.rotate = current.rotate;
newbox.scaleX = current.scaleX;
newbox.scaleY = current.scaleY;
newbox.rotate = data.rotate;
newbox.scaleX = data.scaleX;
newbox.scaleY = data.scaleY;
this.while_reset = true;
this.cropper.setData(newbox);
this.while_reset = false;
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Loading

0 comments on commit 7d27f30

Please sign in to comment.