Skip to content

Commit

Permalink
Wrap calculations for enforceBoundary: false in a conditional (#326)
Browse files Browse the repository at this point in the history
* enclose fixing of data for enforceBoundary: false inside a conditional

* minified version
  • Loading branch information
patrickng authored and thedustinsmith committed May 24, 2017
1 parent cfd4d4d commit 05c8d08
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
36 changes: 19 additions & 17 deletions croppie.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,22 +979,25 @@
ctx.fillStyle = data.backgroundColor;
ctx.fillRect(0, 0, outWidth, outHeight);
}

// start fixing data to send to draw image for enforceBoundary: false
if (left < 0) {
startX = Math.abs(left);
left = 0;
}
if (top < 0) {
startY = Math.abs(top);
top = 0;
}
if (right > self._originalImageWidth) {
width = self._originalImageWidth - left;
outWidth = width;
}
if (bottom > self._originalImageHeight) {
height = self._originalImageHeight - top;
outHeight = height;
if (!self.options.enforceBoundary) {
if (left < 0) {
startX = Math.abs(left);
left = 0;
}
if (top < 0) {
startY = Math.abs(top);
top = 0;
}
if (right > self._originalImageWidth) {
width = self._originalImageWidth - left;
outWidth = width;
}
if (bottom > self._originalImageHeight) {
height = self._originalImageHeight - top;
outHeight = height;
}
}

if (outputRatio !== 1) {
Expand Down Expand Up @@ -1163,8 +1166,7 @@
var RESULT_DEFAULTS = {
type: 'canvas',
format: 'png',
quality: 1,
size: 'viewport'
quality: 1
},
RESULT_FORMATS = ['jpeg', 'webp', 'png'];

Expand Down
Loading

0 comments on commit 05c8d08

Please sign in to comment.