Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to tell if a photo was taken in landscape or portrait? JPEG .NET metadata orientation

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.....

like image 367
ved Avatar asked Apr 08 '10 16:04

ved


People also ask

How do you tell if an image is landscape or portrait?

The length of the longest side determines the orientation. For example, if the height of the image is longer than the width, it is a “portrait” format. Images where the width is longer are called “landscape.”

What is orientation in Exif?

The EXIF orientation value is used by Photoshop and other photo editing software to automatically rotate photos, saving you a manual task.

What is image EXIF data?

EXIF (Exchangeable Image File Format) files store important data about photographs. Almost all digital cameras create these data files each time you snap a new picture. An EXIF file holds all the information about the image itself — such as the exposure level, where you took the photo, and any settings you used.


3 Answers

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.

like image 76
Hans Passant Avatar answered Oct 06 '22 00:10

Hans Passant


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.

http://www.codeproject.com/KB/graphics/NishExifReader.aspx

like image 23
CResults Avatar answered Oct 06 '22 01:10

CResults


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.

like image 43
Alfamale Avatar answered Oct 05 '22 23:10

Alfamale