Skip to content

Instantly share code, notes, and snippets.

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 eleev/c8eb428a306c23f3baf3b7d88666ec8d to your computer and use it in GitHub Desktop.
Save eleev/c8eb428a306c23f3baf3b7d88666ec8d to your computer and use it in GitHub Desktop.
This extension for UIImage fixes image orientation for cases when the iamge was captured using AVFoundation in landscape interface orientation. Swift 3
func landscapeCameraCaptureOrientationFix(for interfaceOrinetation: UIInterfaceOrientation) -> UIImage? {
var imageOrientation: UIImageOrientation!
var shouldOrient: Bool = false
if interfaceOrinetation == .landscapeRight {
imageOrientation = UIImageOrientation.left
shouldOrient = !shouldOrient
} else if interfaceOrinetation == .landscapeLeft {
imageOrientation = UIImageOrientation.right
shouldOrient = !shouldOrient
}
if shouldOrient, let cgimage = self.cgImage {
let image = UIImage(cgImage: cgimage, scale: self.scale, orientation: imageOrientation)
return image
}
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment