#import "UIImage+fixOrientation.h"
@implementationUIImage (fixOrientation)- (UIImage *)fixOrientation{//No-op if the orientation is already correct
if (self.imageOrientation == UIImageOrientationUp) returnself;//We need to calculate the proper transformation to make the image upright.//We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
CGAffineTransform transform =CGAffineTransformIdentity;switch(self.imageOrientation) {caseUIImageOrientationDown:caseUIImageOrientationDownMirrored:
transform=CGAffineTransformTranslate(transform, self.size.width, self.size.height);
transform=CGAffineTransformRotate(transform, M_PI);break;caseUIImageOrientationLeft:caseUIImageOrientationLeftMirrored:
transform= CGAffineTransformTranslate(transform, self.size.width, 0);
transform=CGAffineTransformRotate(transform, M_PI_2);break;caseUIImageOrientationRight:caseUIImageOrientationRightMirrored:
transform= CGAffineTransformTranslate(transform, 0, self.size.height);
transform= CGAffineTransformRotate(transform, -M_PI_2);break;caseUIImageOrientationUp:caseUIImageOrientationUpMirrored:break;
}switch(self.imageOrientation) {caseUIImageOrientationUpMirrored:caseUIImageOrientationDownMirrored:
transform= CGAffineTransformTranslate(transform, self.size.width, 0);
transform= CGAffineTransformScale(tra