You can simply rotate image like this:
UIImage *newImage = [[UIImage alloc] initWithCGImage: myImage.CGImage
scale: 1.0
orientation: UIImageOrientationRight];
This should give you a pointer, than you can decide whether to rotate the image or not by comparing its size for e-g:
if (myImage.size.width < myImage.size.height) {
// its portrait, do the rotation
}