Skip to content

Instantly share code, notes, and snippets.

@NghiaTranUIT
Forked from alejandro-isaza/gist:5717438
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NghiaTranUIT/f657e1cd6d3709d420de to your computer and use it in GitHub Desktop.
Save NghiaTranUIT/f657e1cd6d3709d420de to your computer and use it in GitHub Desktop.
@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