Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
samikha committed Apr 3, 2016
1 parent 7c9c45a commit 3b2c9a5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

> Crop an image in a Cordova app
-Made the color in Android programmable
-For iOS, added this:
https://github.com/kishikawakatsumi/PEPhotoCropEditor/pull/52
And:
https://github.com/kishikawakatsumi/PEPhotoCropEditor/issues/51#issuecomment-72164401


## Install

Expand Down Expand Up @@ -46,4 +52,4 @@ The resulting JPEG quality. default: 100

## License

MIT © [Jeduan Cornejo](https://github.com/jeduan)
MIT © [Jeduan Cornejo](https://github.com/jeduan)
62 changes: 35 additions & 27 deletions src/ios/Lib/PECropRectView.m
Original file line number Diff line number Diff line change
Expand Up @@ -291,40 +291,48 @@ - (CGRect)cropRectMakeWithResizeControlView:(PEResizeControl *)resizeControlView
}
}

CGFloat minWidth = CGRectGetWidth(self.leftEdgeView.bounds) + CGRectGetWidth(self.rightEdgeView.bounds);
if (CGRectGetWidth(rect) < minWidth) {
rect.origin.x = CGRectGetMaxX(self.frame) - minWidth;
rect.size.width = minWidth;
}

CGFloat minHeight = CGRectGetHeight(self.topEdgeView.bounds) + CGRectGetHeight(self.bottomEdgeView.bounds);
if (CGRectGetHeight(rect) < minHeight) {
rect.origin.y = CGRectGetMaxY(self.frame) - minHeight;
rect.size.height = minHeight;
}

CGFloat minWidth = CGRectGetWidth(self.leftEdgeView.bounds) + CGRectGetWidth(self.rightEdgeView.bounds);
CGFloat minHeight = CGRectGetHeight(self.topEdgeView.bounds) + CGRectGetHeight(self.bottomEdgeView.bounds);

if (self.fixedAspectRatio) {
CGRect constrainedRect = rect;

if (CGRectGetWidth(rect) < minWidth) {
constrainedRect.size.width = rect.size.height * (minWidth / rect.size.width);
}

if (CGRectGetHeight(rect) < minHeight) {
constrainedRect.size.height = rect.size.width * (minHeight / rect.size.height);
}

rect = constrainedRect;
}

return rect;
// Compute a minSize for the crop rectangle, then adjust minWidth and minHeight based on the original aspect ratio and the minSize
CGFloat minSize = CGRectGetWidth(self.leftEdgeView.bounds) + CGRectGetWidth(self.rightEdgeView.bounds);
if (self.initialRect.size.width > self.initialRect.size.height) {
minHeight = minSize;
minWidth = minSize * self.initialRect.size.width / self.initialRect.size.height;
} else {
minWidth = minSize;
minHeight = minSize * self.initialRect.size.width / self.initialRect.size.height;
}

if (CGRectGetWidth(rect) < minWidth){
rect.size.width = minWidth;
rect.size.height = rect.size.width * (self.initialRect.size.height / self.initialRect.size.width);
}
if (CGRectGetHeight(rect) < minHeight) {
rect.size.height = minHeight;
rect.size.height = rect.size.height * (self.initialRect.size.width / self.initialRect.size.height);
}
} else {
if (CGRectGetWidth(rect) < minWidth) {
rect.origin.x = CGRectGetMaxX(self.frame) - minWidth;
rect.size.width = minWidth;
}

if (CGRectGetHeight(rect) < minHeight) {
rect.origin.y = CGRectGetMaxY(self.frame) - minHeight;
rect.size.height = minHeight;
}
}
return rect;
}

- (CGRect)constrainedRectWithRectBasisOfWidth:(CGRect)rect aspectRatio:(CGFloat)aspectRatio
{
CGFloat width = CGRectGetWidth(rect);
CGFloat height = CGRectGetHeight(rect);
if (width < height) {
// if (width < height) {
if (self.initialRect.size.width < self.initialRect.size.height) {
height = width / self.fixedAspectRatio;
} else {
height = width * self.fixedAspectRatio;
Expand Down

0 comments on commit 3b2c9a5

Please sign in to comment.