From 7d19fab226c28781d1d45ca7c827f6b8be92c752 Mon Sep 17 00:00:00 2001 From: Florian Rival Date: Sun, 6 Dec 2015 18:04:53 +0100 Subject: [PATCH] Load and resize assets on iOS with proper orientation --- RNImageResizer/ImageResizerModule.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/RNImageResizer/ImageResizerModule.m b/RNImageResizer/ImageResizerModule.m index ac26a2c..e637187 100644 --- a/RNImageResizer/ImageResizerModule.m +++ b/RNImageResizer/ImageResizerModule.m @@ -45,9 +45,18 @@ RCT_EXPORT_METHOD(createResizedImage:(NSString *)path width:(float)width height: // Ask for the "Asset" for the URL. An asset is a representation of an image in the Photo application. [library assetForURL:url resultBlock:^(ALAsset *asset) { - // Here, we have the asset, let's retrieve the image from it - CGImageRef imgRef = [[asset defaultRepresentation] fullResolutionImage]; - UIImage * image = [UIImage imageWithCGImage:imgRef]; + ALAssetRepresentation* representation = [asset defaultRepresentation]; + + // Retrieve the image orientation from the ALAsset + UIImageOrientation orientation = UIImageOrientationUp; + NSNumber* orientationValue = [asset valueForProperty:@"ALAssetPropertyOrientation"]; + if (orientationValue != nil) { + orientation = [orientationValue intValue]; + } + + CGFloat scale = 1; + UIImage* image = [UIImage imageWithCGImage:[representation fullResolutionImage] + scale:scale orientation:orientation]; //Do the resizing UIImage * scaledImage = [image scaleToSize:newSize];