iOS PNG Image rotated 90 degrees

For those that want a Swift solution, create an extension of UIImage and add the following method:

func correctlyOrientedImage() -> UIImage {
    if self.imageOrientation == .up {
        return self

    UIGraphicsBeginImageContextWithOptions(size, false, scale)
    draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
    let normalizedImage = UIGraphicsGetImageFromCurrentImageContext();

    return normalizedImage ?? self;

Leave a Comment