I had also faced the same issue. The only fix that popped out in my mind was to check if the orientation of the image is upright. If it's not upright, we need to get the correct image from the graphics context.
You can write an extension to fix image orientation as follows: (source: here)
extension UIImage {
func fixOrientation() -> UIImage {
if self.imageOrientation == UIImageOrientation.up {
return self
}
UIGraphicsBeginImageContextWithOptions(self.size, false, self.scale)
self.draw(in: CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height))
let normalizedImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return normalizedImage;
}
}
then call the method once you take pic from camera.
chosenImage = chosenImage.fixOrientation()