Skip to content

Commit

Permalink
fix(KonvaImage): inconsistent behavior when scaling
Browse files Browse the repository at this point in the history
(#4)
  • Loading branch information
panzheng committed Oct 8, 2024
1 parent a3d6336 commit 56439a2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/KonvaImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class KonvaImage extends Konva.Image {
ratio = curSize.width / lastSize.width;
newCropWidth = lastCrop.width * ratio;
this.cropWidth(newCropWidth);
if (anchor === "middle-left") {
this.cropX(lastCrop.x + lastCrop.width - newCropWidth);
}
} else {
ratio = lastCrop.height / lastSize.height;
newCropWidth = curSize.width * ratio;
Expand All @@ -79,6 +82,9 @@ class KonvaImage extends Konva.Image {
ratio = curSize.height / lastSize.height;
newCropHeight = lastCrop.height * ratio;
this.cropHeight(newCropHeight);
if (anchor === "top-center") {
this.cropY(lastCrop.y + lastCrop.height - newCropHeight);
}
} else {
ratio = lastCrop.width / lastSize.width;
newCropHeight = curSize.height * ratio;
Expand Down

0 comments on commit 56439a2

Please sign in to comment.