Skip to content

Instantly share code, notes, and snippets.

@sisoje
Last active June 25, 2023 20:32
Show Gist options
  • Save sisoje/8b1d40cb2b6b92e35d5fe1ae1bcfd756 to your computer and use it in GitHub Desktop.
Save sisoje/8b1d40cb2b6b92e35d5fe1ae1bcfd756 to your computer and use it in GitHub Desktop.
Fix UIImage orientation
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