Search code examples
c++iosjpeglibjpeg

How to get JPEG file orientation using libjpeg


I need to know what orientation has the JPEG file which i read.

jpeg_create_decompress(&cinfo);

jpeg_stdio_src(&cinfo, file);
jpeg_read_header(&cinfo, TRUE);

What shall i do after reading the header? Help please


Solution

  • The orientation is stored in the EXIF section.

    I see two options here:

    • Use libexif's jpegtools, see for example: https://github.com/kif/imagizer/blob/master/libexiftran/jpegtools.c (look for the get_orientation() function)

    • or use something like the get_orientation() function used in http://src.gnu-darwin.org/ports/x11-toolkits/gtk20/work/gtk+-2.12.3/gdk-pixbuf/io-jpeg.c to retrieve the orientation from the j_decompress_ptr directly. (this is probably the quickest-to-implement solution)