Skip to content

Commit

Permalink
Fix zoom problems with enforceBoundary turned off (#405)
Browse files Browse the repository at this point in the history
I some situations the result image is scaled out of ratio!
I tagged  down the problem to:
Math.min(width, self._originalImageWidth)
I don't know why its needed ... but if i removed it its working ok!
  • Loading branch information
pknoe3lh authored and thedustinsmith committed Oct 19, 2017
1 parent c70135b commit 83758d1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions croppie.js
Original file line number Diff line number Diff line change
Expand Up @@ -1159,9 +1159,10 @@

if (data.backgroundColor) {
ctx.fillStyle = data.backgroundColor;
ctx.fillRect(0, 0, outWidth, outHeight);
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
}


// start fixing data to send to draw image for enforceBoundary: false
if (!self.options.enforceBoundary) {
if (left < 0) {
Expand All @@ -1181,15 +1182,18 @@
outHeight = height;
}
}
else{
width=Math.min(width, self._originalImageWidth);
height=Math.min(height, self._originalImageHeight)
}

if (outputWidthRatio !== 1 || outputHeightRatio !== 1) {
startX *= outputWidthRatio;
startY *= outputHeightRatio;
outWidth *= outputWidthRatio;
outHeight *= outputHeightRatio;
}

ctx.drawImage(this.elements.preview, left, top, Math.min(width, self._originalImageWidth), Math.min(height, self._originalImageHeight), startX, startY, outWidth, outHeight);
ctx.drawImage(this.elements.preview, left, top, width, height, startX, startY, outWidth, outHeight);
if (circle) {
ctx.fillStyle = '#fff';
ctx.globalCompositeOperation = 'destination-in';
Expand Down

0 comments on commit 83758d1

Please sign in to comment.