I found the following helpful tips:
1. natural way out - landscape
2..width / .height ARE depends on .imageOrientation
3 use short size, not .width
(1) "natural" camera output for IS LANDSCAPE still images .
this is contradictory. portrait is the only way offered by UIImagePickerController, etc. But you will get the UIImageOrientationRight as the “normal” orientation when using the “normal” portrait camera
(The way I remember this is a natural conclusion for the video (of course) landscape, so the still images are the same - even if the iPhone is a portrait.)
(2) .width and .height are really affected by .imageOrientation !!!!!!!!!
Be sure to do this, and try both options on your iPhone,
NSLog(@"fromImage.imageOrientation is %d", fromImage.imageOrientation); NSLog(@"fromImage.size.width %f fromImage.size.height %f", fromImage.size.width, fromImage.size.height);
you will see that the .height and .width variables, even though real pixels are landscape.
(3) just using “short dimension” rather than width can often solve many problems
I found this incredibly useful. Let's say you want perhaps the top square of the image:
CGRect topRectOfOriginal = CGRectMake(0,0, im.size.width,im.size.width);
which doesn’t actually work, you get a squeaky image when the camera (“really”) is held in the landscape.
however, if you just do it
float shortDimension = fminf(im.size.width, im.size.height); CGRect topRectOfOriginal = CGRectMake(0,0, shortDimension,shortDimension);
then “everything fixed”, and you really “don't need to worry about” the orientation flag. Again, point (3) is not a cure, but very often solves all problems.
Hope this helps someone save some time.