Skip to content

Commit

Permalink
Fix rotate (#504)
Browse files Browse the repository at this point in the history
* fix _onZoom called twice when rotate

* keep center point after rotate
  • Loading branch information
swznd authored and thedustinsmith committed May 22, 2018
1 parent 39e648e commit 4bb6c7a
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions croppie.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@
};
}

function _updateCenterPoint() {
function _updateCenterPoint(rotate) {
var self = this,
scale = self._currentZoom,
data = self.elements.preview.getBoundingClientRect(),
Expand All @@ -759,14 +759,27 @@
center = {},
adj = {};

center.y = top / scale;
center.x = left / scale;
if (rotate) {
var cx = pc.x;
var cy = pc.y;
var tx = transform.x;
var ty = transform.y;

adj.y = (center.y - pc.y) * (1 - scale);
adj.x = (center.x - pc.x) * (1 - scale);
center.y = cx;
center.x = cy;
transform.y = tx;
transform.x = ty;
}
else {
center.y = top / scale;
center.x = left / scale;

transform.x -= adj.x;
transform.y -= adj.y;
adj.y = (center.y - pc.y) * (1 - scale);
adj.x = (center.x - pc.x) * (1 - scale);

transform.x -= adj.x;
transform.y -= adj.y;
}

var newCss = {};
newCss[CSS_TRANS_ORG] = center.x + 'px ' + center.y + 'px';
Expand Down Expand Up @@ -1411,8 +1424,8 @@

self.data.orientation = getExifOffset(self.data.orientation, deg);
drawCanvas(canvas, self.elements.img, self.data.orientation);
_updateCenterPoint.call(self, true);
_updateZoomLimits.call(self);
_onZoom.call(self);
}

function _destroy() {
Expand Down

0 comments on commit 4bb6c7a

Please sign in to comment.