From 3b2c9a552abf4382f338ea2f6ec71d1f6a977469 Mon Sep 17 00:00:00 2001 From: Sami Khawam Date: Sun, 3 Apr 2016 15:15:50 -0700 Subject: [PATCH] Included https://github.com/kishikawakatsumi/PEPhotoCropEditor/pull/52 --- README.md | 8 ++++- src/ios/Lib/PECropRectView.m | 62 ++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index f398786..022c8ec 100644 --- a/README.md +++ b/README.md @@ -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 @@ -46,4 +52,4 @@ The resulting JPEG quality. default: 100 ## License -MIT © [Jeduan Cornejo](https://github.com/jeduan) \ No newline at end of file +MIT © [Jeduan Cornejo](https://github.com/jeduan) diff --git a/src/ios/Lib/PECropRectView.m b/src/ios/Lib/PECropRectView.m index dea2eeb..a54c718 100755 --- a/src/ios/Lib/PECropRectView.m +++ b/src/ios/Lib/PECropRectView.m @@ -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;