Last active
June 22, 2017 09:51
-
-
Save alejandro-isaza/5717438 to your computer and use it in GitHub Desktop.
UIImage category to normalize image orientation by rotating an image so that it's orientation is UIImageOrientationUp. Based on http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload/5427890#10611036
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface UIImage (Orientation) | |
- (UIImage*)imageByNormalizingOrientation; | |
@end | |
@implementation UIImage (Orientation) | |
- (UIImage*)imageByNormalizingOrientation { | |
if (self.imageOrientation == UIImageOrientationUp) | |
return self; | |
CGSize size = self.size; | |
UIGraphicsBeginImageContextWithOptions(size, NO, self.scale); | |
[self drawInRect:(CGRect){{0, 0}, size}]; | |
UIImage* normalizedImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
return normalizedImage; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to Swift3
https://gist.github.com/NikhilManapure/42bf67cdc568058938c7ac38d84c4144