From 7e519292b66c22b64b9e1f837b4e93e1be137ecb Mon Sep 17 00:00:00 2001 From: Rastafan Date: Tue, 14 Jan 2020 10:18:13 +0100 Subject: [PATCH 1/8] New parameter: keepAspectRatio -new parameter: keepAspectRatio to edit aspect ratio --- src/ios/CTCrop.m | 4 +++- www/crop.js | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ios/CTCrop.m b/src/ios/CTCrop.m index f3a50e6..a5ec636 100644 --- a/src/ios/CTCrop.m +++ b/src/ios/CTCrop.m @@ -7,6 +7,7 @@ @interface CTCrop () @property (assign) NSUInteger quality; @property (assign) NSUInteger targetWidth; @property (assign) NSUInteger targetHeight; +@property (assign) BOOL keepAspectRatio; @end @implementation CTCrop @@ -19,6 +20,7 @@ - (void) cropImage: (CDVInvokedUrlCommand *) command { self.quality = options[@"quality"] ? [options[@"quality"] intValue] : 100; self.targetWidth = options[@"targetWidth"] ? [options[@"targetWidth"] intValue] : -1; self.targetHeight = options[@"targetHeight"] ? [options[@"targetHeight"] intValue] : -1; + self.keepAspectRatio = options[@"keepAspectRatio"] ? [options[@"keepAspectRatio"] intValue] : 1; NSString *filePrefix = @"file://"; if ([imagePath hasPrefix:filePrefix]) { @@ -45,7 +47,7 @@ - (void) cropImage: (CDVInvokedUrlCommand *) command { CGFloat length = MIN(width, height); cropController.toolbarHidden = YES; cropController.rotationEnabled = NO; - cropController.keepingCropAspectRatio = YES; + cropController.keepingCropAspectRatio = self.keepAspectRatio == 0 ? NO : YES; cropController.imageCropRect = CGRectMake((width - length) / 2, (height - length) / 2, diff --git a/www/crop.js b/www/crop.js index 31fd6e2..c0b2bd3 100644 --- a/www/crop.js +++ b/www/crop.js @@ -4,6 +4,7 @@ var crop = module.exports = function cropImage (success, fail, image, options) { options.quality = options.quality || 100 options.targetWidth = options.targetWidth || -1 options.targetHeight = options.targetHeight || -1 + options.keepAspectRatio = options.keepAspectRatio || 1 return cordova.exec(success, fail, 'CropPlugin', 'cropImage', [image, options]) } From 3927bce45019b9466ddd4fd48374d08fdc5f2323 Mon Sep 17 00:00:00 2001 From: Rastafan Date: Tue, 14 Jan 2020 10:54:01 +0100 Subject: [PATCH 2/8] fix test keepAspectRatio fix test keepAspectRatio --- www/crop.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/crop.js b/www/crop.js index c0b2bd3..a6786ad 100644 --- a/www/crop.js +++ b/www/crop.js @@ -4,7 +4,7 @@ var crop = module.exports = function cropImage (success, fail, image, options) { options.quality = options.quality || 100 options.targetWidth = options.targetWidth || -1 options.targetHeight = options.targetHeight || -1 - options.keepAspectRatio = options.keepAspectRatio || 1 + options.keepAspectRatio = options.keepAspectRatio || options.keepAspectRatio===0 ? options.keepAspectRatio : 1 return cordova.exec(success, fail, 'CropPlugin', 'cropImage', [image, options]) } From 89434f3528d6a2ac73b9a7aa4b375752796df6eb Mon Sep 17 00:00:00 2001 From: Rastafan Date: Tue, 14 Jan 2020 11:31:15 +0100 Subject: [PATCH 3/8] keepAspectRatio doc update keepAspectRatio doc update --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 9eba5fe..70ba3e4 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,10 @@ The resulting JPEG picture width. default: -1 The resulting JPEG picture height. default: -1 + * keepAspectRatio: Number + +Defines if cropping should keep the specified aspect ratio (1) or not (0). default: 1 + ## Ionic / Typescript Example Angular 2 Service From fd9dbc7c969fd8ddb97dc4d64a760aeb60624a58 Mon Sep 17 00:00:00 2001 From: Rastafan Date: Tue, 14 Jan 2020 12:04:06 +0100 Subject: [PATCH 4/8] keepAspectRation on Android keepAspectRation on Android --- src/android/CropPlugin.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/android/CropPlugin.java b/src/android/CropPlugin.java index e1dee93..fb3afaf 100644 --- a/src/android/CropPlugin.java +++ b/src/android/CropPlugin.java @@ -29,6 +29,7 @@ public boolean execute(String action, JSONArray args, final CallbackContext call JSONObject options = args.getJSONObject(1); int targetWidth = options.getInt("targetWidth"); int targetHeight = options.getInt("targetHeight"); + int keepAspectRatio = options.getInt("keepAspectRatio"); this.inputUri = Uri.parse(imagePath); this.outputUri = Uri.fromFile(new File(getTempDirectoryPath() + "/" + System.currentTimeMillis()+ "-cropped.jpg")); @@ -42,11 +43,18 @@ public boolean execute(String action, JSONArray args, final CallbackContext call Crop crop = Crop.of(this.inputUri, this.outputUri); if(targetHeight != -1 && targetWidth != -1) { crop.withMaxSize(targetWidth, targetHeight); - if(targetWidth == targetHeight) { - crop.asSquare(); + if(keepAspectRatio != 0) { + if(targetWidth == targetHeight) { + crop.asSquare(); + }else{ + crop.withAspect(targetWidth, targetHeight); + } } + } else { - crop.asSquare(); + if(keepAspectRatio != 0){ + crop.asSquare(); + } } crop.start(cordova.getActivity()); return true; From 50e9c53b999512307461ed098d65ab44e8a4ddb6 Mon Sep 17 00:00:00 2001 From: Rastafan Date: Tue, 14 Jan 2020 14:44:31 +0100 Subject: [PATCH 5/8] Respect ios targetWidth and targetHeight On iOS, it now respects the size specified with targetWidth and targetHeight, instead of starting always with a square cropped image. If -1 is specified on one of the two dimension, that dimension is replaced by the picture corrisponding dimension. --- src/ios/CTCrop.m | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ios/CTCrop.m b/src/ios/CTCrop.m index a5ec636..6773659 100644 --- a/src/ios/CTCrop.m +++ b/src/ios/CTCrop.m @@ -4,9 +4,9 @@ @interface CTCrop () @property (copy) NSString* callbackId; -@property (assign) NSUInteger quality; -@property (assign) NSUInteger targetWidth; -@property (assign) NSUInteger targetHeight; +@property (assign) NSInteger quality; +@property (assign) NSInteger targetWidth; +@property (assign) NSInteger targetHeight; @property (assign) BOOL keepAspectRatio; @end @@ -44,15 +44,11 @@ - (void) cropImage: (CDVInvokedUrlCommand *) command { CGFloat width = self.targetWidth > -1 ? (CGFloat)self.targetWidth : image.size.width; CGFloat height = self.targetHeight > -1 ? (CGFloat)self.targetHeight : image.size.height; - CGFloat length = MIN(width, height); cropController.toolbarHidden = YES; cropController.rotationEnabled = NO; cropController.keepingCropAspectRatio = self.keepAspectRatio == 0 ? NO : YES; - cropController.imageCropRect = CGRectMake((width - length) / 2, - (height - length) / 2, - length, - length); + cropController.imageCropRect = CGRectMake(0, 0, width, height); self.callbackId = command.callbackId; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:cropController]; From a509ddb009069731a9ec46ea79818e7939df4bdd Mon Sep 17 00:00:00 2001 From: Rastafan Date: Wed, 15 Jan 2020 11:53:18 +0100 Subject: [PATCH 6/8] version bump 0.3.2 + doc fix version bump and install command fix --- README.md | 2 +- plugin.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 70ba3e4..3b79ef3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Install ``` -$ cordova plugin add --save cordova-plugin-crop +$ cordova plugin add --save https://github.com/rastafan/cordova-plugin-crop ``` diff --git a/plugin.xml b/plugin.xml index c4de9a1..cbb7c23 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="0.3.2"> CropPlugin From e7ae05851592530f72fb2a7319b330d3f45eee4d Mon Sep 17 00:00:00 2001 From: Rastafan Date: Tue, 8 Sep 2020 22:06:53 +0200 Subject: [PATCH 7/8] Fix crop ratio for iOS Fixed crop ratio for iOS. Now it works in the same way as Android. --- src/ios/CTCrop.m | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ios/CTCrop.m b/src/ios/CTCrop.m index 6773659..f3e61a3 100644 --- a/src/ios/CTCrop.m +++ b/src/ios/CTCrop.m @@ -42,8 +42,22 @@ - (void) cropImage: (CDVInvokedUrlCommand *) command { cropController.delegate = self; cropController.image = image; - CGFloat width = self.targetWidth > -1 ? (CGFloat)self.targetWidth : image.size.width; - CGFloat height = self.targetHeight > -1 ? (CGFloat)self.targetHeight : image.size.height; + CGFloat width; + CGFloat height; + + if(self.targetWidth != -1 && self.targetHeight != -1){ + width = (CGFloat)self.targetWidth; + height = (CGFloat)self.targetHeight; + } else { + if(self.keepAspectRatio != 0){ + width = MIN(image.size.width, image.size.height); + height = width; + } else { + width = image.size.width; + height = image.size.height; + } + } + cropController.toolbarHidden = YES; cropController.rotationEnabled = NO; cropController.keepingCropAspectRatio = self.keepAspectRatio == 0 ? NO : YES; From 7d31d2bba8ee054694fc473c66fb7a6cf2f97a34 Mon Sep 17 00:00:00 2001 From: Rastafan Date: Tue, 8 Sep 2020 22:16:48 +0200 Subject: [PATCH 8/8] bump version --- package.json | 2 +- plugin.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 48172b6..2b0152d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-crop", - "version": "0.4.0", + "version": "0.3.3", "description": "Crop an image in a Cordova app", "cordova": { "id": "cordova-plugin-crop", diff --git a/plugin.xml b/plugin.xml index cbb7c23..349c25b 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="0.3.3"> CropPlugin