Take the 2-minute tour ×

Thru VB.net/C# is there any way to read any metadata of off a JPEG to tell if the photo was taken in landscape or portrait?

I would assume a camera would need an accelerometer first of all to even tell what direction is up...correct? Assuming there is that kind of intelligence to detect the angle of tilt, how would I go about reading that info from a JPEG?

I found some samples online to read metadata with vb/.net not sure what to read to find the info i need.

Appreciate any pointers.....

share|improve this question
add comment

4 Answers

up vote 4 down vote accepted

This project should do what you want:


And this guy already has an implementation:


share|improve this answer
thank you...this is great, now I only need to find out if the camera does indeed output orientation info –  ved Apr 8 '10 at 18:11
add comment

Yes, there's an EXIF tag that can store the orientation. Tag number 274, values are documented here. Sample code to read the tags from the JPEG data is available here.

share|improve this answer
Second link is now dead it seems –  andrewb Feb 21 at 0:22
I fixed it..... –  Hans Passant Feb 21 at 9:42
Cheers, and thanks for the easy tag number reference –  andrewb Feb 23 at 23:13
add comment

A lot of digital cameras now have sensors within them to detect if the picture was taken in landscape or portrait mode. They then store this information in the header of the JPG. This data is known as EXIF.

Here is a pretty good tutorial on extracting the EXIF data from a JPG file. In addition to portrait/landscape info you can also extract (usually) the model/make of camera, lens settings, time/date etc.


share|improve this answer
add comment

Would it be sufficient to simply compare the width of the JPG image to its height and if width > height, treat as landscape?

I have done this in C# before (although I can't remember the implementation details now but I remember it wasn't particularly difficult, a couple of lines of code only) for a website I worked on which required uploaded JPGs to be displayed within a frame (such as you might hang on your wall) and we needed to know whether to add the landscape or portrait version of the frame.

share|improve this answer
Only problem with this is you don't know which way the photographer rotated the camera. I always tend to rotate to the left but my (left handed) wife rotates to the right.. the camera that is :-) –  CResults Apr 8 '10 at 16:30
what if someone held the camera at an oblique angle to take the pic? the width will always exceed the height...w/o being able to sense Z direction you wouldnt be able to tell. –  ved Apr 8 '10 at 18:10
Good points. Thinking about it, the project I was involved with could always assume that the image had been processed before upload and thus would arrive in the correct format. –  Alfamale Apr 9 '10 at 11:32
add comment

Your Answer


