From ea5d3baafdbe1fd4f3043c78a4d843eeb2f5b811 Mon Sep 17 00:00:00 2001 From: CSullivan102 Date: Sat, 11 Jan 2014 12:42:39 -0500 Subject: [PATCH] Added fullSizeImage option to return full size images. Updated docs --- README.md | 25 +++++++++++++++++++++++-- src/ios/SOSPicker.h | 1 + src/ios/SOSPicker.m | 15 +++++++++++---- www/imagepicker.js | 21 ++++++++++----------- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4cefb62..32a64e6 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ cordova plugin add https://github.com/CSullivan102/cordova-imagePicker.git The plugin creates the object `window.imagePicker` with the method `getPictures(success, fail, options)` -Example: +Example - Get Full Size Images (all default options): ```javascript window.imagePicker.getPictures( function(results) { @@ -32,7 +32,25 @@ window.imagePicker.getPictures( } }, function (error) { console.log('Error: ' + error); - }, options + } +); +``` + +Example - Get at most 10 images scaled to width of 800: +```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); + }, { + maximumImagesCount: 10, + fullSizeImage: 0, + width: 800, + height: 800 + } ); ``` @@ -43,6 +61,9 @@ 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. + fullSizeImage: bool, + // whether to return the full size image, defaults to true. If this value + // is true, width and height are ignored. width: int, // width to resize image to (if one of height/width is 0, will resize // to fit the other while keeping aspect ratio) diff --git a/src/ios/SOSPicker.h b/src/ios/SOSPicker.h index 71081ec..71d7c02 100644 --- a/src/ios/SOSPicker.h +++ b/src/ios/SOSPicker.h @@ -20,5 +20,6 @@ @property (nonatomic, assign) NSInteger width; @property (nonatomic, assign) NSInteger height; @property (nonatomic, assign) NSInteger quality; +@property (nonatomic, assign) bool fullSizeImage; @end diff --git a/src/ios/SOSPicker.m b/src/ios/SOSPicker.m index fd95d60..c1126b9 100644 --- a/src/ios/SOSPicker.m +++ b/src/ios/SOSPicker.m @@ -22,6 +22,7 @@ NSDictionary *options = [command.arguments objectAtIndex: 0]; NSInteger maximumImagesCount = [[options objectForKey:@"maximumImagesCount"] integerValue]; + self.fullSizeImage = [[options objectForKey:@"fullSizeImage"] boolValue]; self.width = [[options objectForKey:@"width"] integerValue]; self.height = [[options objectForKey:@"height"] integerValue]; self.quality = [[options objectForKey:@"quality"] integerValue]; @@ -60,10 +61,16 @@ UIImage* image = nil; image = [dict objectForKey:UIImagePickerControllerOriginalImage]; - CGSize targetSize = CGSizeMake(self.width, self.height); - UIImage* scaledImage = nil; - scaledImage = [self imageByScalingNotCroppingForSize:image toSize:targetSize]; - NSData* data = UIImageJPEGRepresentation(scaledImage, self.quality/100.0f); + NSData* data = nil; + if (self.fullSizeImage == YES) { + data = UIImageJPEGRepresentation(image, self.quality/100.0f); + } else { + CGSize targetSize = CGSizeMake(self.width, self.height); + UIImage* scaledImage = nil; + scaledImage = [self imageByScalingNotCroppingForSize:image toSize:targetSize]; + data = UIImageJPEGRepresentation(scaledImage, self.quality/100.0f); + } + NSString* docsPath = [NSTemporaryDirectory()stringByStandardizingPath]; NSError* err = nil; diff --git a/www/imagepicker.js b/www/imagepicker.js index d05a15e..802a2cf 100644 --- a/www/imagepicker.js +++ b/www/imagepicker.js @@ -13,9 +13,14 @@ var ImagePicker = function() { * success - success callback * fail - error callback * options -* .maximumImagesCount -* .maxWidth -* .maxHeight +* .maximumImagesCount - 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. +* .fullSizeImage - whether to return the full size image, defaults to true. If this value +* is true, width and height are ignored. +* .width - width to resize image to (if one of height/width is 0, will resize to fit the +* other while keeping aspect ratio) +* .height - height to resize image to +* .quality - quality of resized image, defaults to 100 */ ImagePicker.prototype.getPictures = function(success, fail, options) { if (!options) { @@ -24,6 +29,7 @@ ImagePicker.prototype.getPictures = function(success, fail, options) { var params = { maximumImagesCount: options.maximumImagesCount ? options.maximumImagesCount : 15, + fullSizeImage: (typeof options.fullSizeImage !== "undefined") ? options.fullSizeImage : 1, width: options.width ? options.width : 0, height: options.height ? options.height : 0, quality: options.quality ? options.quality : 100 @@ -32,11 +38,4 @@ ImagePicker.prototype.getPictures = function(success, fail, options) { return cordova.exec(success, fail, "ImagePicker", "getPictures", [params]); }; -cordova.addConstructor(function() { - window.imagePicker = new ImagePicker(); - - // backwards compatibility - window.plugins = window.plugins || {}; - window.plugins.imagePicker = window.imagePicker; - console.log("Image Picker Registered under window.imagePicker"); -}); +window.imagePicker = new ImagePicker();