Permalink
Browse files

Fix Image.getSize() according to image orientation

Summary:
This is fix for issue #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 #15690

Differential Revision: D5731414

Pulled By: shergin

fbshipit-source-id: 7ced00ac7ac812c91216dccf0c76acd0e913dda0
  • Loading branch information...
doochik authored and facebook-github-bot committed Aug 30, 2017
1 parent 63f9901 commit ccc11f2f30ec6d61e570df31fcbfa3ae82ea85f1
Showing with 24 additions and 4 deletions.
  1. +24 −4 Libraries/Image/RCTImageLoader.m
@@ -716,10 +716,30 @@ - (RCTImageLoaderCancellationBlock)getImageSizeForURLRequest:(NSURLRequest *)ima
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){

0 comments on commit ccc11f2

Please sign in to comment.