Merge pull request #1290 from Snapp-FidMe/force_portrait_on_ios

Add ability to force portrait orientation on IOS
This commit is contained in:
João Guilherme Fidelis 2018-02-26 10:11:40 -03:00 committed by GitHub
commit 6f69f7b033
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 0 deletions

View File

@ -246,6 +246,8 @@ Supported options:
- `exif` (boolean true or false) Use this with `true` if you want a exif data map of the picture taken on the return data of your promise. If no value is specified `exif:false` is used. - `exif` (boolean true or false) Use this with `true` if you want a exif data map of the picture taken on the return data of your promise. If no value is specified `exif:false` is used.
- `forceUpOrientation` (iOS only, boolean true or false). This property allows to force portrait orientation based on actual data instead of exif data.
The promise will be fulfilled with an object with some of the following properties: The promise will be fulfilled with an object with some of the following properties:
- `width`: returns the image's width (taking image orientation into account) - `width`: returns the image's width (taking image orientation into account)

View File

@ -324,6 +324,9 @@ static NSDictionary *defaultFaceDetectorOptions = nil;
if ([options[@"mirrorImage"] boolValue]) { if ([options[@"mirrorImage"] boolValue]) {
takenImage = [RNImageUtils mirrorImage:takenImage]; takenImage = [RNImageUtils mirrorImage:takenImage];
} }
if ([options[@"forceUpOrientation"] boolValue]) {
takenImage = [RNImageUtils forceUpOrientation:takenImage];
}
NSMutableDictionary *response = [[NSMutableDictionary alloc] init]; NSMutableDictionary *response = [[NSMutableDictionary alloc] init];
float quality = [options[@"quality"] floatValue]; float quality = [options[@"quality"] floatValue];
@ -336,6 +339,8 @@ static NSDictionary *defaultFaceDetectorOptions = nil;
if ([options[@"base64"] boolValue]) { if ([options[@"base64"] boolValue]) {
response[@"base64"] = [takenImageData base64EncodedStringWithOptions:0]; response[@"base64"] = [takenImageData base64EncodedStringWithOptions:0];
} }
if ([options[@"exif"] boolValue]) { if ([options[@"exif"] boolValue]) {
int imageRotation; int imageRotation;

View File

@ -14,6 +14,7 @@
+ (UIImage *)generatePhotoOfSize:(CGSize)size; + (UIImage *)generatePhotoOfSize:(CGSize)size;
+ (UIImage *)cropImage:(UIImage *)image toRect:(CGRect)rect; + (UIImage *)cropImage:(UIImage *)image toRect:(CGRect)rect;
+ (UIImage *)mirrorImage:(UIImage *)image; + (UIImage *)mirrorImage:(UIImage *)image;
+ (UIImage *)forceUpOrientation:(UIImage *)image;
+ (NSString *)writeImage:(NSData *)image toPath:(NSString *)path; + (NSString *)writeImage:(NSData *)image toPath:(NSString *)path;
+ (void)updatePhotoMetadata:(CMSampleBufferRef)imageSampleBuffer withAdditionalData:(NSDictionary *)additionalData inResponse:(NSMutableDictionary *)response; + (void)updatePhotoMetadata:(CMSampleBufferRef)imageSampleBuffer withAdditionalData:(NSDictionary *)additionalData inResponse:(NSMutableDictionary *)response;

View File

@ -68,6 +68,17 @@
return [fileURL absoluteString]; return [fileURL absoluteString];
} }
+ (UIImage *)forceUpOrientation:(UIImage *)image
{
if (image.imageOrientation != UIImageOrientationUp) {
UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
return image;
}
+ (void)updatePhotoMetadata:(CMSampleBufferRef)imageSampleBuffer withAdditionalData:(NSDictionary *)additionalData inResponse:(NSMutableDictionary *)response + (void)updatePhotoMetadata:(CMSampleBufferRef)imageSampleBuffer withAdditionalData:(NSDictionary *)additionalData inResponse:(NSMutableDictionary *)response
{ {
CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL); CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);