login
Header Space

 
 

Changing the Default Orientation of a JPEG-EXIF File.txt

July 28, 2008 - 8:30am
Submitted by Eus on July 28, 2008 - 8:30am.

When browsing a bunch of pictures with Kuickshow, I always saw that all pictures were correctly oriented for display. The pictures that were taken by rotating the camera 90 degrees from its natural position were displayed by Kuickshow in the right orientation so that I did not have to re-orient the pictures manually. When I edited one of such pictures with the GIMP, the picture was displayed as it was, which was in the wrong orientation to be viewed.

Naturally, I reoriented the picture with the GIMP so that it could be easily viewed. I oriented it 90 degrees clock-wise. After saving the picture and quited the GIMP, I opened the picture again with Kuickshow. This time, however, Kuickshow displayed the picture in the wrong orientation so that I had to rotate it 270 degrees clock-wise by pressing `9', which is Kuickshow shortcut to rotate a picture 90 degrees clock-wise, three times. At this, I realized that there was a special field in the picture file format, which is a JPEG, that told Kuickshow the orientation of the picture when it was taken.

To correct this field, I opened the file with `vi', which naturally displayed the content of the file in hexadecimal view. Beside that, I also opened with `vi' in another tab of Konsole, another picture that was taken by the same camera in the natural position. Next, I performed a manual visual comparison of the contents of the files by switching from one tab to another tab pressing `alt + left arrow' and `alt + right arrow' back and forth. In the parts of the files that both `vi' displayed for the very first time, there was a single field at location 0x48 that altered from 0x01 to 0x06. I suspected this field to be the one that told Kuickshow how to orient the picture correctly for display because it was only one byte, which is suitable for use as flag. So, I changed 0x06 to 0x01, and I got it right. The picture was displayed correctly by Kuickshow.

Well, actually what I have done is a trade-off between reading the EXIF II meta-data specification and reverse-engineering the file format completely. However, getting the flag under three minutes had its own fun and was faster than searching the specification somewhere on the Internet. I showed the parts of the files that both `vi' displayed for the very first time below.

 offset    0  1  2  3   4  5  6  7   8  9  a  b   c  d  e  f  0123456789abcdef
00000000 d8 ff e0  00 10 4a 46  49 46 00 01  01 01 00 48  ÿØÿà..JFIF.....H
00000010  00 48 00 00  ff e1 48 18  45 78 69 66  00 00 49 49  .H..ÿáH.Exif..II
00000020  2a 00 08 00  00 00 09 00  0f 01 02 00  06 00 00 00  *...............
00000030  7a 00 00 00  10 01 02 00  17 00 00 00  80 00 00 00  z...............
00000040  12 01 03 00  01 00 00 00  01 00 00 00  1a 01 05 00  ................
00000050  01 00 00 00  98 00 00 00  1b 01 05 00  01 00 00 00  ................
00000060  a0 00 00 00  28 01 03 00  01 00 00 00  02 00 00 00   ...(...........
00000070  32 01 02 00  14 00 00 00  a8 00 00 00  13 02 03 00  2.......¨.......
00000080  01 00 00 00  02 00 00 00  69 87 04 00  01 00 00 00  ........i.......
00000090  bc 00 00 00  22 23 00 00  43 61 6e 6f  6e 00 43 61  ¼..."#..Canon.Ca
000000a0  6e 6f 6e 20  45 4f 53 20  33 35 30 44  20 44 49 47  non EOS 350D DIG
000000b0  49 54 41 4c  00 00 48 00  00 00 01 00  00 00 48 00  ITAL..H.......H.
000000c0  00 00 01 00  00 00 32 30  30 38 3a 30  36 3a 30 33  ......2008:06:03
000000d0  20 31 32 3a  34 35 3a 30  33 00 1c 00  9a 82 05 00   12:45:03.......
000000e0  01 00 00 00  12 02 00 00  9d 82 05 00  01 00 00 00  ................
000000f0  1a 02 00 00  22 88 03 00  01 00 00 00  01 00 00 00  ...."...........

 offset    0  1  2  3   4  5  6  7   8  9  a  b   c  d  e  f  0123456789abcdef
00000100  27 88 03 00  01 00 00 00  40 06 00 00  00 90 07 00  '.......@.......
00000110  04 00 00 00  30 32 32 31  03 90 02 00  14 00 00 00  ....0221........
00000120  22 02 00 00  04 90 02 00  14 00 00 00  36 02 00 00  "...........6...
00000130  01 91 07 00  04 00 00 00  01 02 03 00  01 92 0a 00  ................
00000140  01 00 00 00  4a 02 00 00  02 92 05 00  01 00 00 00  ....J...........
00000150  52 02 00 00  04 92 0a 00  01 00 00 00  5a 02 00 00  R...........Z...
00000160  07 92 03 00  01 00 00 00  05 00 00 00  09 92 03 00  ................
00000170  01 00 00 00  49 00 00 00  0a 92 05 00  01 00 00 00  ....I...........
00000180  62 02 00 00  7c 92 07 00  8a 20 00 00  6a 02 00 00  b...|.... ..j...
00000190  86 92 07 00  00 00 00 00  00 00 00 00  00 a0 07 00  ............. ..
000001a0  04 00 00 00  30 31 30 30  01 a0 03 00  01 00 00 00  ....0100. ......
000001b0  01 00 00 00  02 a0 03 00  01 00 00 00  80 0d 00 00  ..... ..........
000001c0  03 a0 03 00  01 00 00 00  00 09 00 00  0e a2 05 00  . ...........¢..
000001d0  01 00 00 00  f4 22 00 00  0f a2 05 00  01 00 00 00  ....ô"...¢......
000001e0  fc 22 00 00  10 a2 03 00  01 00 00 00  02 00 00 00  ü"...¢..........
000001f0  01 a4 03 00  01 00 00 00  00 00 00 00  02 a4 03 00  .¤...........¤..

 offset    0  1  2  3   4  5  6  7   8  9  a  b   c  d  e  f  0123456789abcdef
00000200  01 00 00 00  01 00 00 00  03 a4 03 00  01 00 00 00  .........¤......
00000210  00 00 00 00  06 a4 03 00  01 00 00 00  00 00 00 00  .....¤..........
00000220  05 a0 04 00  01 00 00 00  04 23 00 00  00 00 00 00  . .......#......
00000230  01 00 00 00  1e 00 00 00  28 00 00 00  0a 00 00 00  ........(.......
00000240  32 30 30 38  3a 30 36 3a  30 33 20 31  32 3a 34 35  2008:06:03 12:45
00000250  3a 30 33 00  32 30 30 38  3a 30 36 3a  30 33 20 31  :03.2008:06:03 1
00000260  32 3a 34 35  3a 30 33 00  2a e8 04 00  00 00 01 00  2:45:03.*è......

Figure 1 -- The Picture Taken In The Natural Position Of The Camera

 offset    0  1  2  3   4  5  6  7   8  9  a  b   c  d  e  f  0123456789abcdef
00000000 d8 ff e0  00 10 4a 46  49 46 00 01  01 01 00 48  ÿØÿà..JFIF.....H
00000010  00 48 00 00  ff e1 3e 9a  45 78 69 66  00 00 49 49  .H..ÿá>.Exif..II
00000020  2a 00 08 00  00 00 09 00  0f 01 02 00  06 00 00 00  *...............
00000030  7a 00 00 00  10 01 02 00  17 00 00 00  80 00 00 00  z...............
00000040  12 01 03 00  01 00 00 00  06 00 00 00  1a 01 05 00  ................
00000050  01 00 00 00  98 00 00 00  1b 01 05 00  01 00 00 00  ................
00000060  a0 00 00 00  28 01 03 00  01 00 00 00  02 00 00 00   ...(...........
00000070  32 01 02 00  14 00 00 00  a8 00 00 00  13 02 03 00  2.......¨.......
00000080  01 00 00 00  02 00 00 00  69 87 04 00  01 00 00 00  ........i.......
00000090  bc 00 00 00  22 23 00 00  43 61 6e 6f  6e 00 43 61  ¼..."#..Canon.Ca
000000a0  6e 6f 6e 20  45 4f 53 20  33 35 30 44  20 44 49 47  non EOS 350D DIG
000000b0  49 54 41 4c  00 00 48 00  00 00 01 00  00 00 48 00  ITAL..H.......H.
000000c0  00 00 01 00  00 00 32 30  30 38 3a 30  36 3a 30 33  ......2008:06:03
000000d0  20 31 32 3a  35 33 3a 34  34 00 1c 00  9a 82 05 00   12:53:44.......
000000e0  01 00 00 00  12 02 00 00  9d 82 05 00  01 00 00 00  ................
000000f0  1a 02 00 00  22 88 03 00  01 00 00 00  01 00 00 00  ...."...........

 offset    0  1  2  3   4  5  6  7   8  9  a  b   c  d  e  f  0123456789abcdef
00000100  27 88 03 00  01 00 00 00  90 01 00 00  00 90 07 00  '...............
00000110  04 00 00 00  30 32 32 31  03 90 02 00  14 00 00 00  ....0221........
00000120  22 02 00 00  04 90 02 00  14 00 00 00  36 02 00 00  "...........6...
00000130  01 91 07 00  04 00 00 00  01 02 03 00  01 92 0a 00  ................
00000140  01 00 00 00  4a 02 00 00  02 92 05 00  01 00 00 00  ....J...........
00000150  52 02 00 00  04 92 0a 00  01 00 00 00  5a 02 00 00  R...........Z...
00000160  07 92 03 00  01 00 00 00  05 00 00 00  09 92 03 00  ................
00000170  01 00 00 00  49 00 00 00  0a 92 05 00  01 00 00 00  ....I...........
00000180  62 02 00 00  7c 92 07 00  8a 20 00 00  6a 02 00 00  b...|.... ..j...
00000190  86 92 07 00  00 00 00 00  00 00 00 00  00 a0 07 00  ............. ..
000001a0  04 00 00 00  30 31 30 30  01 a0 03 00  01 00 00 00  ....0100. ......
000001b0  01 00 00 00  02 a0 03 00  01 00 00 00  80 0d 00 00  ..... ..........
000001c0  03 a0 03 00  01 00 00 00  00 09 00 00  0e a2 05 00  . ...........¢..
000001d0  01 00 00 00  f4 22 00 00  0f a2 05 00  01 00 00 00  ....ô"...¢......
000001e0  fc 22 00 00  10 a2 03 00  01 00 00 00  02 00 00 00  ü"...¢..........
000001f0  01 a4 03 00  01 00 00 00  00 00 00 00  02 a4 03 00  .¤...........¤..

 offset    0  1  2  3   4  5  6  7   8  9  a  b   c  d  e  f  0123456789abcdef
00000200  01 00 00 00  01 00 00 00  03 a4 03 00  01 00 00 00  .........¤......
00000210  00 00 00 00  06 a4 03 00  01 00 00 00  00 00 00 00  .....¤..........
00000220  05 a0 04 00  01 00 00 00  04 23 00 00  00 00 00 00  . .......#......
00000230  01 00 00 00  1e 00 00 00  32 00 00 00  0a 00 00 00  ........2.......
00000240  32 30 30 38  3a 30 36 3a  30 33 20 31  32 3a 35 33  2008:06:03 12:53
00000250  3a 34 34 00  32 30 30 38  3a 30 36 3a  30 33 20 31  :44.2008:06:03 1
00000260  32 3a 35 33  3a 34 34 00  2a e8 04 00  00 00 01 00  2:53:44.*è......

Figure 2 -- The Picture Taken By Rotating The Camera 90 Degrees Clock-wise

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <b> <quote> <pre> <hr> <br> <p> <img> <blockquote> <font> <tt> <table> <tr> <i>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

speck-geostationary