How to know if photo in Landscape or Portrait mode?

mikezang picture mikezang · Feb 3, 2011 · Viewed 8.9k times · Source

I load photo from iPhone/iPad library, most of them in Portrait mode, I want to know How can I check the photo in Landscape or Portrait mode?

Answer

Björn Marschollek picture Björn Marschollek · Feb 3, 2011

Use the imageOrientation property of UIImage instances. It is going to return you one of these constants.

Example:

UIImage *image = // loaded from library

if (image.imageOrientation == UIImageOrientationUp) {
    NSLog(@"portrait");
} else if (image.imageOrientation == UIImageOrientationLeft || image.imageOrientation == UIImageOrientationRight) {
    NSLog(@"landscape");
}