Last active
June 25, 2023 20:32
-
-
Save sisoje/8b1d40cb2b6b92e35d5fe1ae1bcfd756 to your computer and use it in GitHub Desktop.
Fix UIImage orientation
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
extension UIImage { | |
var fixOrientationTransform: CGAffineTransform { | |
let angle = CGFloat((imageOrientation.rawValue & 2) >> 1 - ((imageOrientation.rawValue & 1) << 1)) * .pi / 2 | |
let flipX = CGFloat(1 - ((imageOrientation.rawValue & 4) >> 1)) | |
return CGAffineTransform(scaleX: flipX, y: 1).rotated(by: angle) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment