mirror of
https://gitee.com/shuto/cordova-imagePicker.git
synced 2026-05-23 00:05:03 +08:00
Added fullSizeImage option to return full size images. Updated docs
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
+11
-4
@@ -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;
|
||||
|
||||
+10
-11
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user