Camera image orientation issue

Hi there,

I’m working on a CMS which allows the user to crop uploaded images.

Everything works fine when I test with random digital imagery which I have on my hard-drive. When I come to test using the client’s digital images he has given me, all the images come out landscape regardless of their orientation.

I am resizing the images programmatically using PHP. Even though my OS is happy with this flashy “portait” orientation idea, getimagesize() returns landscape dimentions. So when the files are resized and saved by PHP, they are all landscape. My guess is the client’s camera is pretty old skool, and cannot distinguish between landscape and portrait orientation. He would then (I guess) orientate them manually using his PC. This data, for whatever reason, is not saved to the jpeg file, or at least not in a way that PHP can read.

Short of batch cropping the images in Photoshop, and then re-saving them, which of course is no good to my client, is there anything I can do to get these images the right way round!?

Many thanks,

Strange, but if so, can you still count the pixels of the image? Actually, maybe you could upload of these images for us to look at and/or test?

Its probably the EXIF Orientation Tag. Some software take it into consideration others ignore it.
ImageMagick has an [URL=“”]auto-orient option to handle it.

Thanks guys for your replies.

ImagicMagick seems awesome, but unfortunately my server doesn’t have it installed.

However, EXIF is loaded on my server’s php build. Fandabidosy. And yes, exif_read_data() returns an extensive array, of which ‘Orientation’ contains a number between 1 and 8, which gives the orientation of the image. You can then use rotateimage() on a GD resource (assuming you have GD installed), to rotate the image. Bonza.

For anyone who’s interested there’s a great post about it here: