diff --git a/CHANGELOD.md b/CHANGELOD.md index 9f1c6f8c..2f931905 100644 --- a/CHANGELOD.md +++ b/CHANGELOD.md @@ -1,3 +1,8 @@ +## [2.0.5](https://github.com/spoonconsulting/cordova-plugin-telerik-imagepicker/compare/2.0.4...2.0.5) (2023-11-10) + +* **android:** Return the Height and Width of selected images along with their paths. +* **ios:** Return the Height and Width of selected images along with their paths. + ## [2.0.4](https://github.com/spoonconsulting/cordova-plugin-telerik-imagepicker/compare/2.0.3...2.0.4) (2023-07-12) * **ios:** Use interfaceOrientation for ios 13+. diff --git a/README.md b/README.md index 1f686a28..4c299ae5 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,9 @@ Example - Get Full Size Images (all default options): window.imagePicker.getPictures( function(results) { for (var i = 0; i < results.length; i++) { - console.log('Image URI: ' + results[i]); + console.log('Image URI: ' + results[i].path); + console.log('Image Height: ' + results[i].height); + console.log('Image Width: ' + results[i].width); } }, function (error) { console.log('Error: ' + error); @@ -40,7 +42,9 @@ Example - Get at most 10 images scaled to width of 800: window.imagePicker.getPictures( function(results) { for (var i = 0; i < results.length; i++) { - console.log('Image URI: ' + results[i]); + console.log('Image URI: ' + results[i].path); + console.log('Image Height: ' + results[i].height); + console.log('Image Width: ' + results[i].width); } }, function (error) { console.log('Error: ' + error); diff --git a/package-lock.json b/package-lock.json index 49a786f9..53c04523 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@spoonconsulting/cordova-plugin-telerik-imagepicker", - "version": "2.0.4", + "version": "2.0.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@spoonconsulting/cordova-plugin-telerik-imagepicker", - "version": "2.0.4", + "version": "2.0.5", "license": "MIT", "engines": { "name": "cordova", diff --git a/package.json b/package.json index 26a0a33b..54af4a13 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@spoonconsulting/cordova-plugin-telerik-imagepicker", - "version": "2.0.4", + "version": "2.0.5", "cordova_name": "ImagePicker", "description": "This plugin allows selection of multiple images from the camera roll / gallery in a phonegap app", "license": "MIT", diff --git a/plugin.xml b/plugin.xml index 01185328..58bd3897 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="2.0.5"> ImagePicker diff --git a/src/android/ImagePicker.java b/src/android/ImagePicker.java index 3149e678..68d9ecae 100644 --- a/src/android/ImagePicker.java +++ b/src/android/ImagePicker.java @@ -8,6 +8,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.database.Cursor; +import android.graphics.BitmapFactory; import android.graphics.Color; import android.net.Uri; import android.os.Build; @@ -76,6 +77,7 @@ public boolean execute(String action, final JSONArray args, final CallbackContex public void onActivityResult(int requestCode, int resultCode, Intent data) { ExecutorService executor = Executors.newSingleThreadExecutor(); + ArrayList imageInfos = new ArrayList<>(); executor.execute(() -> { try { cordova.getActivity().runOnUiThread(() -> { @@ -111,7 +113,18 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } } } - JSONArray res = new JSONArray(fileURIs); + for (int i=0; i < fileURIs.size(); i++) { + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + Uri ImageUri = Uri.parse(fileURIs.get(i)); + BitmapFactory.decodeFile(new File(ImageUri.getPath()).getAbsolutePath(), options); + JSONObject json = new JSONObject(); + json.put("path", fileURIs.get(i)); + json.put("width", options.outWidth); + json.put("height", options.outHeight); + imageInfos.add(json); + } + JSONArray res = new JSONArray(imageInfos); callbackContext.success(res); } else if (resultCode == Activity.RESULT_CANCELED && data != null) { String error = data.getStringExtra("ERRORMESSAGE"); diff --git a/src/ios/SOSPicker.m b/src/ios/SOSPicker.m index fc4bcbf5..cbbe5d02 100644 --- a/src/ios/SOSPicker.m +++ b/src/ios/SOSPicker.m @@ -182,7 +182,7 @@ - (void)assetsPickerController:(GMImagePickerController *)picker didFinishPickin NSLog(@"GMImagePicker: User finished picking assets. Number of selected items is: %lu", (unsigned long)fetchArray.count); - NSMutableArray * result_all = [[NSMutableArray alloc] init]; + NSMutableArray * resultList = [[NSMutableArray alloc] init]; CGSize targetSize = CGSizeMake(self.width, self.height); NSFileManager* fileMgr = [[NSFileManager alloc] init]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); @@ -201,17 +201,24 @@ - (void)assetsPickerController:(GMImagePickerController *)picker didFinishPickin do { filePath = [NSString stringWithFormat:@"%@/%@.%@", libPath, [[NSUUID UUID] UUIDString], @"jpg"]; } while ([fileMgr fileExistsAtPath:filePath]); - + NSData* data = nil; if (self.width == 0 && self.height == 0) { // no scaling required if (self.outputType == BASE64_STRING){ UIImage* image = [UIImage imageNamed:item.image_fullsize]; - [result_all addObject:[UIImageJPEGRepresentation(image, self.quality/100.0f) base64EncodedStringWithOptions:0]]; + NSDictionary *imageInfo = @{@"path":[UIImageJPEGRepresentation(image, self.quality/100.0f) base64EncodedStringWithOptions:0], + @"width": [NSNumber numberWithFloat:image.size.width], + @"height": [NSNumber numberWithFloat:image.size.height]}; + [resultList addObject: imageInfo]; } else { if (self.quality == 100) { // no scaling, no downsampling, this is the fastest option - [result_all addObject:item.image_fullsize]; + UIImage* image = [UIImage imageNamed:item.image_fullsize]; + NSDictionary *imageInfo = @{@"path":item.image_fullsize, + @"width": [NSNumber numberWithFloat:image.size.width], + @"height": [NSNumber numberWithFloat:image.size.height]}; + [resultList addObject: imageInfo]; } else { // resample first @@ -221,7 +228,10 @@ - (void)assetsPickerController:(GMImagePickerController *)picker didFinishPickin result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]]; break; } else { - [result_all addObject:[[NSURL fileURLWithPath:filePath] absoluteString]]; + NSDictionary *imageInfo = @{@"path":[[NSURL fileURLWithPath:filePath] absoluteString], + @"width": [NSNumber numberWithFloat:image.size.width], + @"height": [NSNumber numberWithFloat:image.size.height]}; + [resultList addObject: imageInfo]; } } } @@ -236,16 +246,22 @@ - (void)assetsPickerController:(GMImagePickerController *)picker didFinishPickin break; } else { if(self.outputType == BASE64_STRING){ - [result_all addObject:[data base64EncodedStringWithOptions:0]]; + NSDictionary *imageInfo = @{@"path":[data base64EncodedStringWithOptions:0], + @"width": [NSNumber numberWithFloat:scaledImage.size.width], + @"height": [NSNumber numberWithFloat:scaledImage.size.height]}; + [resultList addObject: imageInfo]; } else { - [result_all addObject:[[NSURL fileURLWithPath:filePath] absoluteString]]; + NSDictionary *imageInfo = @{@"path":[[NSURL fileURLWithPath:filePath] absoluteString], + @"width": [NSNumber numberWithFloat:scaledImage.size.width], + @"height": [NSNumber numberWithFloat:scaledImage.size.height]}; + [resultList addObject: imageInfo]; } } } } if (result == nil) { - result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:result_all]; + result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:resultList]; } [self.viewController dismissViewControllerAnimated:YES completion:nil];