diff --git a/README.md b/README.md
index 46a6ad8..5c190fd 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,53 @@
cordova-imagePicker
===================
-Cordova Plugin For Multiple Image Selection
+Cordova Plugin For Multiple Image Selection - currently implemented only for
+iOS, Android coming soon.
+## Installing the plugin
+The plugin conforms to the Cordova plugin specification, it can be installed
+using the Cordova / Phonegap command line interface.
+
+```
+phonegap plugin add https://github.com/CSullivan102/cordova-imagePicker.git
+
+cordova plugin add https://github.com/CSullivan102/cordova-imagePicker.git
+```
+
+## Using the plugin
+
+The plugin creates the object `window.imagePicker` with the method `getPictures(success, fail, options)`
+
+Example:
+```javascript
+window.imagePicker.getPictures(
+ function(results) {
+ for (var i = 0; i < results.length; i++) {
+ console.log('Image URI: ' + results[i]);
+ }
+ }, function (error) {
+ console.log('Error: ' + error);
+ }, options
+);
+```
+
+### Options
+
+```javascript
+options = {
+ maximumImagesCount: int,
+ // max images to be selected, defaults to 15. If this is set to 1, upon
+ // selection of a single image, the plugin will return it.
+ width: int,
+ // width to resize image to (if one of height/width is 0, will resize
+ // to fit the other while keeping aspect ratio)
+ height: int,
+ // height to resize image to
+ quality: int (0-100)
+ // quality of resized image, defaults to 100
+};
+```
This plugin uses the ELCImagePickerController for the iOS image picker.
diff --git a/plugin.xml b/plugin.xml
index c817f01..475b5d2 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -14,7 +14,9 @@
-
+
+
+
@@ -26,9 +28,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file
+
diff --git a/src/ios/ELCImagePicker/ELCAlbumPickerController.h b/src/ios/ELCImagePicker/ELCAlbumPickerController.h
index 2f9057b..151c0f7 100644
--- a/src/ios/ELCImagePicker/ELCAlbumPickerController.h
+++ b/src/ios/ELCImagePicker/ELCAlbumPickerController.h
@@ -14,8 +14,8 @@
@property (nonatomic, weak) id parent;
@property (nonatomic, strong) NSMutableArray *assetGroups;
-@property (nonatomic, weak) BOOL singleSelection;
-@property (nonatomic, weak) BOOL immediateReturn;
+@property (nonatomic, assign) BOOL singleSelection;
+@property (nonatomic, assign) BOOL immediateReturn;
// optional, can be used to filter the assets displayed
@property (nonatomic, weak) id assetPickerFilterDelegate;
diff --git a/src/ios/SOSPicker.h b/src/ios/SOSPicker.h
index 5c6c660..71081ec 100644
--- a/src/ios/SOSPicker.h
+++ b/src/ios/SOSPicker.h
@@ -10,13 +10,15 @@
#import "ELCAlbumPickerController.h"
#import "ELCImagePickerController.h"
-@interface SOSPicker : CDVPlugin
+@interface SOSPicker : CDVPlugin
@property (copy) NSString* callbackId;
- (void) getPictures:(CDVInvokedUrlCommand *)command;
-- (void) elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info;
-- (void) elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker;
- (UIImage*)imageByScalingNotCroppingForSize:(UIImage*)anImage toSize:(CGSize)frameSize;
+@property (nonatomic, assign) NSInteger width;
+@property (nonatomic, assign) NSInteger height;
+@property (nonatomic, assign) NSInteger quality;
+
@end
diff --git a/src/ios/SOSPicker.m b/src/ios/SOSPicker.m
index 41c9954..fd95d60 100644
--- a/src/ios/SOSPicker.m
+++ b/src/ios/SOSPicker.m
@@ -19,12 +19,17 @@
@synthesize callbackId;
- (void) getPictures:(CDVInvokedUrlCommand *)command {
- NSString* maxPhotos = [command.arguments objectAtIndex:0];
+ NSDictionary *options = [command.arguments objectAtIndex: 0];
+
+ NSInteger maximumImagesCount = [[options objectForKey:@"maximumImagesCount"] integerValue];
+ self.width = [[options objectForKey:@"width"] integerValue];
+ self.height = [[options objectForKey:@"height"] integerValue];
+ self.quality = [[options objectForKey:@"quality"] integerValue];
// Create the an album controller and image picker
ELCAlbumPickerController *albumController = [[ELCAlbumPickerController alloc] init];
- int max = [maxPhotos intValue];
- if (max == 1) {
+
+ if (maximumImagesCount == 1) {
albumController.immediateReturn = true;
albumController.singleSelection = true;
} else {
@@ -33,10 +38,11 @@
}
ELCImagePickerController *imagePicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
- imagePicker.maximumImagesCount = max;
-
- [albumController setParent:imagePicker];
- [imagePicker setDelegate:self];
+ imagePicker.maximumImagesCount = maximumImagesCount;
+ imagePicker.returnsOriginalImage = 1;
+ imagePicker.imagePickerDelegate = self;
+
+ albumController.parent = imagePicker;
self.callbackId = command.callbackId;
// Present modally
[self.viewController presentViewController:imagePicker
@@ -54,11 +60,10 @@
UIImage* image = nil;
image = [dict objectForKey:UIImagePickerControllerOriginalImage];
- //Hard code this for now...
- CGSize targetSize = CGSizeMake(750,960);
+ CGSize targetSize = CGSizeMake(self.width, self.height);
UIImage* scaledImage = nil;
scaledImage = [self imageByScalingNotCroppingForSize:image toSize:targetSize];
- NSData* data = UIImageJPEGRepresentation(scaledImage, 50/100.0f);
+ NSData* data = UIImageJPEGRepresentation(scaledImage, self.quality/100.0f);
NSString* docsPath = [NSTemporaryDirectory()stringByStandardizingPath];
NSError* err = nil;
@@ -72,12 +77,16 @@
if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]];
+ break;
} else {
[resultStrings addObject:[[NSURL fileURLWithPath:filePath] absoluteString]];
}
}
+
+ if (nil == result) {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:resultStrings];
+ }
- result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:resultStrings];
[self.viewController dismissViewControllerAnimated:YES completion:nil];
[self.commandDelegate sendPluginResult:result callbackId:self.callbackId];
}
@@ -106,7 +115,11 @@
CGFloat heightFactor = targetHeight / height;
// opposite comparison to imageByScalingAndCroppingForSize in order to contain the image within the given bounds
- if (widthFactor > heightFactor) {
+ if (widthFactor == 0.0) {
+ scaleFactor = heightFactor;
+ } else if (heightFactor == 0.0) {
+ scaleFactor = widthFactor;
+ } else if (widthFactor > heightFactor) {
scaleFactor = heightFactor; // scale to fit height
} else {
scaleFactor = widthFactor; // scale to fit width
diff --git a/www/imagepicker.js b/www/imagepicker.js
index 3c84af9..d05a15e 100644
--- a/www/imagepicker.js
+++ b/www/imagepicker.js
@@ -1,3 +1,4 @@
+/*global cordova,window,console*/
/**
* An Image Picker plugin for Cordova
*
@@ -8,10 +9,34 @@ var ImagePicker = function() {
};
-ImagePicker.prototype.getPictures = function() {
+/*
+* success - success callback
+* fail - error callback
+* options
+* .maximumImagesCount
+* .maxWidth
+* .maxHeight
+*/
+ImagePicker.prototype.getPictures = function(success, fail, options) {
+ if (!options) {
+ options = {};
+ }
+
+ var params = {
+ maximumImagesCount: options.maximumImagesCount ? options.maximumImagesCount : 15,
+ width: options.width ? options.width : 0,
+ height: options.height ? options.height : 0,
+ quality: options.quality ? options.quality : 100
+ };
-}
+ return cordova.exec(success, fail, "ImagePicker", "getPictures", [params]);
+};
-cordova.addContstructor(function() {
+cordova.addConstructor(function() {
window.imagePicker = new ImagePicker();
-});
\ No newline at end of file
+
+ // backwards compatibility
+ window.plugins = window.plugins || {};
+ window.plugins.imagePicker = window.imagePicker;
+ console.log("Image Picker Registered under window.imagePicker");
+});