@@ -23,6 +23,7 @@ - (void) getPictures:(CDVInvokedUrlCommand *)command {
23
23
24
24
NSDictionary *options = [command.arguments objectAtIndex: 0 ];
25
25
NSInteger maximumImagesCount = [[options objectForKey: @" maximumImagesCount" ] integerValue ];
26
+ self.width = [[options objectForKey: @" width" ] integerValue ];
26
27
27
28
QBImagePickerController *imagePickerController = [QBImagePickerController new ];
28
29
imagePickerController.delegate = self;
@@ -47,17 +48,33 @@ - (void)qb_imagePickerController:(QBImagePickerController *)imagePickerControlle
47
48
NSMutableArray *resultStrings = [[NSMutableArray alloc ] init ];
48
49
PHImageRequestOptions * imageRequestOptions = [[PHImageRequestOptions alloc ] init ];
49
50
imageRequestOptions.synchronous = YES ;
50
-
51
+
51
52
52
53
for (PHAsset *asset in assets) {
53
54
// Do something with the asset
54
55
if (asset.mediaType == PHAssetMediaTypeImage)
55
56
{
56
- [[PHImageManager defaultManager ] requestImageDataForAsset: asset options: imageRequestOptions resultHandler: ^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
57
- // NSString *encodedString = [imageData base64Encoding];
58
-
59
- NSString *encodedString = [imageData base64EncodedStringWithOptions: 0 ];
60
- [resultStrings addObject: encodedString];
57
+ // [[PHImageManager defaultManager] requestImageDataForAsset:asset options:imageRequestOptions resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
58
+ // NSString *encodedString = [imageData base64Encoding];
59
+ // NSString *encodedString = [imageData base64EncodedStringWithOptions:0];
60
+ // [resultStrings addObject: encodedString];
61
+ // }];
62
+
63
+ float imageWidth = asset.pixelWidth ;
64
+ float imageHeight = asset.pixelHeight ;
65
+ CGSize newImageSize;
66
+
67
+ // Keep aspect ratio
68
+ if (self.width ){
69
+ self.height = (width * imageHeight) / imageWidth;
70
+ newImageSize = CGSizeMake (width, height);
71
+ }
72
+ else {
73
+ newImageSize = CGSizeMake (imageWidth, imageHeight);
74
+ }
75
+ // Resize the image
76
+ [[PHImageManager defaultManager ] requestImageForAsset: asset targetSize: newImageSize contentMode: PHImageContentModeAspectFit options: imageRequestOptions resultHandler: ^(UIImage *result, NSDictionary *info) {
77
+ [resultStrings addObject: [self encodeToBase64String: result]];
61
78
}];
62
79
}
63
80
}
0 commit comments