Fix Image.getSize() according to image orientation

Summary:
This is fix for issue https://github.com/facebook/react-native/issues/14097

I've prepared images with different exif orientation (https://yadi.sk/d/is_xcEEo3MRAxF)
0-4 should have size 200x100
5-8 should have size 100x200
Closes https://github.com/facebook/react-native/pull/15690

Differential Revision: D5731414

Pulled By: shergin

fbshipit-source-id: 7ced00ac7ac812c91216dccf0c76acd0e913dda0
This commit is contained in:
Aleksei Androsov 2017-08-30 00:21:13 -07:00 committed by Facebook Github Bot
parent 63f990121a
commit ccc11f2f30
1 changed files with 24 additions and 4 deletions

View File

@ -716,10 +716,30 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image,
CGSize size;
if ([imageOrData isKindOfClass:[NSData class]]) {
NSDictionary *meta = RCTGetImageMetadata(imageOrData);
size = (CGSize){
[meta[(id)kCGImagePropertyPixelWidth] doubleValue],
[meta[(id)kCGImagePropertyPixelHeight] doubleValue],
};
NSInteger imageOrientation = [meta[(id)kCGImagePropertyOrientation] integerValue];
switch (imageOrientation) {
case kCGImagePropertyOrientationLeft:
case kCGImagePropertyOrientationRight:
case kCGImagePropertyOrientationLeftMirrored:
case kCGImagePropertyOrientationRightMirrored:
// swap width and height
size = (CGSize){
[meta[(id)kCGImagePropertyPixelHeight] doubleValue],
[meta[(id)kCGImagePropertyPixelWidth] doubleValue],
};
break;
case kCGImagePropertyOrientationUp:
case kCGImagePropertyOrientationDown:
case kCGImagePropertyOrientationUpMirrored:
case kCGImagePropertyOrientationDownMirrored:
default:
size = (CGSize){
[meta[(id)kCGImagePropertyPixelWidth] doubleValue],
[meta[(id)kCGImagePropertyPixelHeight] doubleValue],
};
break;
}
} else {
UIImage *image = imageOrData;
size = (CGSize){