I have a bunch of mixed images, some portrait orientation, some landscape, which I want to be processed by Mathematica. When I Import them Mathematica handles them all as landscape image, also when resaving, even though e.g. Photoshop and Directory Opus are aware of the orientation. (Windows Explorer isn't.)
Is there a way Mathematica can tell when an image was created in landscape or portrait?

I'm using version


1 Answer 1


Orientation is not part of the image itself; it is stored as metadata. In version 10.1 at least it seems that this data is respected. One can also read this value using the Import element "CameraTopOrientation":

Import["file.jpg", {"JPEG", "CameraTopOrientation"}]

A numeric value can be read from "Exif":

"Orientation" /. Import["file.jpg", {"JPEG", "Exif"}]

The meaning of these values is described here: http://sylvana.net/jpegcrop/exif_orientation.html

If Mathematica does not handle this automatically for some reason you should at least to able to read the value and rotate it as required. That is unless you set the orientation in an external utility that keeps the data in a "sidecar" file of some sort that only it reads.

  • $\begingroup$ Thanks, Wizard (again! :-)). Works in version 9 too, but I couldn't find any of this information in the help system. $\endgroup$
    – stevenvh
    Commented Jul 21, 2015 at 16:00
  • $\begingroup$ @Steven You're welcome, as always. By the way I noticed that you stopped answering questions on Electronics.SE; I don't mean to pry but I am curious why? $\endgroup$
    – Mr.Wizard
    Commented Jul 21, 2015 at 19:35
  • $\begingroup$ Yeah, I haven't been there in years. (Too) busy with other things. However, every now and again I get an electronics question via my site (it's on my profile), and I still try to help people out. $\endgroup$
    – stevenvh
    Commented Jul 22, 2015 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.