Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ios): Implement property 'quality' in captureImage() (CB-11630) #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ capturing a video clip, the `CaptureErrorCB` callback executes with a
### iOS Quirks

- The __limit__ parameter is not supported, and only one image is taken per invocation.
- iOS supports an additional __quality__ property, to allow modification of the JPEG compression quality. The value must be greather than or equal to 0 and less than or equal to 1 (defaults to 0.5).
See [here](https://developer.apple.com/reference/uikit/1624115-uiimagejpegrepresentation?language=objc) for more details.


## CaptureVideoOptions
Expand Down
2 changes: 2 additions & 0 deletions src/ios/CDVCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ typedef NSUInteger CDVCaptureError;
{
CDVImagePicker* pickerController;
BOOL inUse;
CGFloat jpegCompression;
}
@property BOOL inUse;
@property CGFloat jpegCompression;
- (void)captureAudio:(CDVInvokedUrlCommand*)command;
- (void)captureImage:(CDVInvokedUrlCommand*)command;
- (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCallbackId:(NSString*)callbackId;
Expand Down
13 changes: 11 additions & 2 deletions src/ios/CDVCapture.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ - (void)viewWillAppear:(BOOL)animated {

@implementation CDVCapture
@synthesize inUse;
@synthesize jpegCompression;

- (void)pluginInitialize
{
self.inUse = NO;
self.jpegCompression = 0.5;
}

- (void)captureAudio:(CDVInvokedUrlCommand*)command
Expand Down Expand Up @@ -128,9 +130,16 @@ - (void)captureImage:(CDVInvokedUrlCommand*)command
options = [NSDictionary dictionary];
}

// options could contain limit and mode neither of which are supported at this time
// options could contain limit, mode and quality
// taking more than one picture (limit) is only supported if provide own controls via cameraOverlayView property
// can support mode in OS
NSNumber* quality = [options objectForKey:@"quality"];
if (quality) {
CGFloat qualityValue = [quality floatValue];
if (qualityValue >= 0 && qualityValue <= 1) {
self.jpegCompression = qualityValue;
}
}

if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
NSLog(@"Capture.imageCapture: camera not available.");
Expand Down Expand Up @@ -178,7 +187,7 @@ - (CDVPluginResult*)processImage:(UIImage*)image type:(NSString*)mimeType forCal
if (mimeType && [mimeType isEqualToString:@"image/png"]) {
data = UIImagePNGRepresentation(image);
} else {
data = UIImageJPEGRepresentation(image, 0.5);
data = UIImageJPEGRepresentation(image, self.jpegCompression);
}

// write to temp directory and return URI
Expand Down