The Metadata in TIFF files » History » Revision 10
Revision 9 (Robin Mills, 12 Nov 2016 17:45) → Revision 10/20 (Robin Mills, 13 Nov 2016 08:58)
h1. The Metadata in TIFF files
The Tagged Image File Format is a container. It's very flexible and can deal with multiple pages, different colour spaces, frame configurations as well as metadata. The specification is available from: https://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
!Tiff.png!
The format consists of an 8 byte header which provides a 2 byte endian flag (II or MM), a 2 byte type "magic number" (42) and a 4 byte offset to an _*Image File Directory*_.
The _*IFD*_ _(Image File Directory)_ has a two byte header which contains the length of the directory followed by 12 byte field or "tag". The trailing 4 bytes of the the directory is always the offset to the next dictionary _*or*_ zero to terminate the directory chain.
A tag consists of a 12 byte record: TagID, TagType, Count and Offset which are 2,2,4 and 4 bytes respectively. The TagID defines the purpose of the record (Width, Height, ColorSpace etc) and the TagType defines the data format. Count and Offset are used to contain the raw data _*or*_ provide an offset in the file at which to read the raw data for this tag.
This is described in the specification. The code in tiff image.cpp/ TiffImage::printStructure() decodes the dictionaries.
The TIFF container is so flexible it is used as the structure for most RAW formats including Adobe's DNG. Additionally the TIFF container is used to store the metadata that lies inside the Exif blocks embedded in JPEG and PNG files.
There is a 64bit version of Tiff called _*BigTiff*_. This is currently not supported by exiv2.
*Example:*
The version of exiv2(.exe) which ships with v0.25 provides options _*<code>-pS</code>*_ to reveals the structure of the TIFF and option _*<code>-pX</code>*_ is used to extract the raw XMP/xml data.
The option _*<code>-pa</code>*_ -pa is used to print the metadata in human readable format.<pre>$ exiv2 -pa test/data/test.tiff ~/tif
$ exiv2 -pa test/data/test.tiff
Exif.Image.NewSubfileType Long 1 Primary image
Exif.Image.ImageWidth Short 1 282 40
Exif.Image.ImageLength Short 1 212 470
Exif.Image.BitsPerSample Short 3 8 8 8
Exif.Image.Compression Short 1 LZW
Exif.Image.PhotometricInterpretation Short 1 RGB
Exif.Image.ImageDescription Ascii 32
Exif.Image.Make Ascii 5 SONY
Exif.Image.Model Ascii 9 DSC-S600
Exif.Image.StripOffsets Long 16 1 4372 ... 2694
Exif.Image.Orientation Short 1 top, left right, top
Exif.Image.SamplesPerPixel Short 1 3
Exif.Image.RowsPerStrip Long Short 1 14 1092
Exif.Image.StripByteCounts Long 16 10492 ...
Exif.Image.XResolution Rational 1 96 5086
Exif.Image.YResolution Rational 1 96
Exif.Image.PlanarConfiguration Short 1 1
Exif.Image.ResolutionUnit Short 1 inch
Exif.Image.DateTime Ascii 20 2009:04:26 12:38:18
Exif.Image.Predictor Short 1 No prediction scheme used Horizontal differencing
Exif.Image.SampleFormat Short 3 Unsigned integer data
Exif.Image.XMLPacket Byte 2505 2500 (Binary value suppressed)
Exif.Image.InterColorProfile Undefined 1352 (Binary value suppressed)
Xmp.dc.title LangAlt 1 lang="x-default" this is a test image title
/Users/rmills/tif: (No IPTC data found in the file)
$ exiv2 -pS ~/tif
STRUCTURE OF TIFF FILE (II): test/data/test.tiff FILE: /Users/rmills/tif
address | tag | type | count | offset | value
10 | 0x00fe NewSubfileType | LONG | 1 | 0 | 0
22 | 0x0100 ImageWidth | SHORT | 1 | 282 2621440 | 282 40
34 22 | 0x0101 ImageLength | SHORT | 1 | 212 30801920 | 212 470
46 34 | 0x0102 BitsPerSample | SHORT | 3 | 290 182 | 8 8 8
58
46 | 0x0103 Compression | SHORT | 1 | 5 327680 | 5
70 58 | 0x0106 PhotometricInterpretation PhotometricInterpret | SHORT | 1 | 2 131072 | 2
82 70 | 0x010e ImageDescription | ASCII | 32 | 296 |
94 | 0x010f Make | ASCII | 5 | 328 | SONY
106 | 0x0110 Model | ASCII | 9 | 334 | DSC-S600
118 | 0x0111 StripOffsets | LONG | 16 1 | 344 2694 | 4372 14864 25634 37110 50496 ...
130 0
82 | 0x0112 Orientation | SHORT | 1 | 1 393216 | 1
142 6
94 | 0x0115 SamplesPerPixel | SHORT | 1 | 3 196608 | 3
154 106 | 0x0116 RowsPerStrip | LONG SHORT | 1 | 14 71565312 | 14 1092
166 118 | 0x0117 StripByteCounts | LONG | 16 | 408 | 10492 10770 11476 13385 13348 ...
178 | 0x011a XResolution | RATIONAL | 1 | 472 5086 | 96/1 0
190 130 | 0x011b YResolution | RATIONAL | 1 | 480 | 96/1
202 | 0x011c PlanarConfiguration | SHORT | 1 | 1 65536 | 1
214 142 | 0x0128 ResolutionUnit 0x013d Predictor | SHORT | 1 | 2 131072 | 2
226 154 | 0x0132 DateTime | ASCII | 20 | 488 | 2009:04:26 12:38:18
238 | 0x013d Predictor | SHORT | 1 | 1 | 1
250 | 0x0153 SampleFormat | SHORT | 3 | 508 188 | 1 1 1
262
166 | 0x02bc XMLPacket | BYTE | 2505 2500 | 514 194 | <?xpacket begin="..." id="W5M0Mp ...
274 | 0x8773 InterColorProfile | UNDEFINED | 1352 | 3020 | ...Happl. ..scnrRGB XYZ ....... ...
END test/data/test.tiff
$ exiv2 -pX test/data/test.tiff ~/tif | xmllint --format -pretty 1 -
<?xml version="1.0"?>
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about="">
<dc:title>
<rdf:Alt>
<rdf:li xml:lang="x-default">this is a test image</rdf:li> title</rdf:li>
</rdf:Alt>
</dc:title>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
855 rmills@rmillsmbp:~/Documents/exiv2 $ </pre>You </pre>
You can use the output from _*<code>-pS</code>*_ to determine the location of the XMLPacket:<pre>$ exiv2 -pS --grep XML test/data/test.tiff | grep XMLPacket
262 | 0x02bc XMLPacket | BYTE | 2505 | 514 | <?xpacket begin="..." id="W5M0Mp ...
$ </pre>You can clearly see the XMLPacket of 2505 bytes is stored at offset 514. 194 into the file and consists of 2500 bytes. You can of course directly extract the XMP with the following command which says: set the block size to 1 byte, skip 514 194 bytes and extract 2505 bytes:
<pre>$ dump the next 2500 bytes:<pre>863 rmills@rmillsmbp:~/Documents/exiv2 $ dd bs=1 count=2505 skip=514 if=test/data/test.tiff skip=194 count=2500 if=~/tif | xmllint --format -pretty 1 -
2505+0
2500+0 records in
2505+0 2500+0 records out
2505 2500 bytes (2.5 kB) copied, 0.0064 s, 391 kB/s transferred in 0.005714 secs (437526 bytes/sec)
<?xml version="1.0"?>
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about="">
<dc:title>
<rdf:Alt>
<rdf:li xml:lang="x-default">this is a test image</rdf:li> title</rdf:li>
</rdf:Alt>
</dc:title>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
864 rmills@rmillsmbp:~/Documents/exiv2 $ </pre>The option _*<code>-pX</code>*_ doesn't actually use dd to achieve the same result and is much more convenient to use.
To demonstrate that the metadata block in a JPEG is a TIFF file, extract and print the structure.<pre>$ exiv2 -pS test/data/Reagan.jpg ~/jpg
$ exiv2 -pS test/data/Reagan.jpg
STRUCTURE OF JPEG FILE: test/data/Reagan.jpg /Users/rmills/jpg
address | marker | length length | data
0 2 | 0xffd8 0xd8 SOI
2 4 | 0xffe1 0xe1 APP1 | 5718 14862 | Exif..MM.*......................
5722 Exif..II*.....................
14868 | 0xffed APP13 | 3038 | Photoshop 3.0.8BIM..........Z...
8762 | 0xffe1 0xe1 APP1 | 5329 2720 | http://ns.adobe.com/xap/1.0/.<?x http://ns.adobe.com/xap/1.0/.<
14093 17590 | 0xffe2 APP2 0xed APP13 | 576 110 | ICC_PROFILE......0ADBE....mntrRG chunk 1/1 Photoshop 3.0.8BIM.......6....
14671 17702 | 0xffee APP14 0xe2 APP2 | 14 4094 | Adobe.d@...... MPF.II*...............0100....
14687 21798 | 0xffdb 0xdb DQT | 132
14821 21932 | 0xffc0 0xc0 SOF0 | 17
14840 21951 | 0xffdd DRI | 4
14846 | 0xffc4 0xc4 DHT | 418
15266 22371 | 0xffda 0xda SOS
| 12
$ </pre> We can extract the APP1/Exif data as follows:<pre>$ dd bs=1 skip=$((2+2+8)) count=$((5718-8)) if=test/data/Reagan.jpg of=ReaganExif.tiff skip=12 count=14862 if=~/jpg of=bull.tif
5710+0 14862+0 records in
5710+0 14862+0 records out
5710 14862 bytes (5.7 kB) copied, 0.026688 s, 214 kB/s transferred in 0.038783 secs (383211 bytes/sec)
$ exiv2 -pS ReaganExif.tif
bull.tif
STRUCTURE OF TIFF FILE (MM): ReaganExif.tif FILE: bull.tif
address | tag | type | count | offset | value
10 | 0x0100 ImageWidth | SHORT | 1 | 13107200 | 200
22 | 0x0101 ImageLength | SHORT | 1 | 8519680 | 130
34 | 0x0102 BitsPerSample | SHORT | 4 | 242 | 8 8 8 8
46 | 0x0103 Compression | SHORT | 1 | 65536 | 1
58 | 0x0106 PhotometricInterpretation | SHORT | 1 | 131072 | 2
70 | 0x010e ImageDescription | ASCII | 403 | 250 | 040621-N-6536T-062.USS Ronald Re ...
82 | 0x010f Make | ASCII | 18 | 653 134 | NIKON CORPORATION CORPORATION.
94 22 | 0x0110 Model | ASCII | 10 12 | 671 152 | NIKON D1X
106 D5300.
34 | 0x0112 Orientation | SHORT | 1 | 65536 | 1
118 | 0x0115 SamplesPerPixel | SHORT | 1
46 | 262144 | 4
130 | 0x011a XResolution | RATIONAL | 1 | 681 164 | 3000000/10000
142
58 | 0x011b YResolution | RATIONAL | 1 | 689 172 | 3000000/10000
154
70 | 0x011c PlanarConfiguration 0x0128 ResolutionUnit | SHORT | 1 | 65536 | 1
166 | 0x0128 ResolutionUnit | SHORT | 1 2 | 131072 | 2
178
82 | 0x0131 Software | ASCII | 40 10 | 697 180 | Adobe Photoshop Elements 12.0 Ma ...
190 Ver.1.00 .
94 | 0x0132 DateTime | ASCII | 20 | 737 190 | 2016:09:13 11:58:16 2015:02:13 20:46:51.
202 106 | 0x013b Artist 0x0213 YCbCrPositioning | ASCII SHORT | 34 1 | 757 1 | Photographer..s Mate 3rd Class ( ... 1
214 118 | 0x8769 ExifTag | LONG | 1 | 792 | 792
226 | 0x8825 GPSTag | LONG 210 | 1 | 1400 | 1400 210
1422 4080 | 0x0103 Compression | SHORT | 1 | 393216 6 | 6
1434 4092 | 0x011a XResolution | RATIONAL | 1 | 1498 4168 | 72/1
1446
4104 | 0x011b YResolution | RATIONAL | 1 | 1506 4176 | 72/1
1458
4116 | 0x0128 ResolutionUnit | SHORT | 1 | 131072 2 | 2
1470 4128 | 0x0201 JPEGInterchangeFormat JPEGInterchangeForma | LONG | 1 | 1514 4184 | 1514 4184
1482 4140 | 0x0202 JPEGInterchangeFormatLeng JPEGInterchangeForma | LONG | 1 | 4196 10670 | 4196 10670
4152 | 0x0213 YCbCrPositioning | SHORT | 1 | 1 | 1
END ReaganExif.tif
$ </pre>The version of the exiv2 command-line program that ships with v0.26 later has an option _*<code>-pR</code>*_ which _*Recursively*_ with recursively prints the structure of an image file. By *_Recursively*_ means *_recursive*_ we mean the utility will print the structures which are embedded within while reside inside other structures. For example, the Exif metadata in a JPEG is a encoded as a TIFF embedded in the file. <pre>$ <pre>543 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -pR test/data/Reagan.jpg
STRUCTURE OF JPEG FILE: test/data/Reagan.jpg
address | marker | length | data
0 | 0xffd8 SOI
2 | 0xffe1 APP1 | 5718 | Exif..MM.*......................
STRUCTURE OF TIFF FILE (MM): MemIo
address | tag | type | count | offset | value
10 | 0x0100 ImageWidth | SHORT | 1 | 13107200 | 200
22 | 0x0101 ImageLength | SHORT | 1 | 8519680 | 130
34 | 0x0102 BitsPerSample | SHORT | 4 | 242 | 8 8 8 8
46 | 0x0103 Compression | SHORT | 1 | 65536 | 1
58 | 0x0106 PhotometricInterpretation | SHORT | 1 | 131072 | 2
70 | 0x010e ImageDescription | ASCII | 403 | 250 | 040621-N-6536T-062.USS Ronald Re ...
82 | 0x010f Make | ASCII | 18 | 653 | NIKON CORPORATION
94 | 0x0110 Model | ASCII | 10 | 671 | NIKON D1X
106 | 0x0112 Orientation | SHORT | 1 | 65536 | 1
118 | 0x0115 SamplesPerPixel | SHORT | 1 | 262144 | 4
130 | 0x011a XResolution | RATIONAL | 1 | 681 | 681/0
142 | 0x011b YResolution | RATIONAL | 1 | 689 | 689/0
154 | 0x011c PlanarConfiguration | SHORT | 1 | 65536 | 1
166 | 0x0128 ResolutionUnit | SHORT | 1 | 131072 | 2
178 | 0x0131 Software | ASCII | 40 | 697 | Adobe Photoshop Elements 12.0 Ma ...
190 | 0x0132 DateTime | ASCII | 20 | 737 | 2016:09:13 11:58:16
202 | 0x013b Artist | ASCII | 34 | 757 | Photographer..s Mate 3rd Class ( ...
214 | 0x8769 ExifTag | LONG | 1 | 792 | 792
STRUCTURE OF TIFF FILE (MM): MemIo
address | tag | type | count | offset | value
794 | 0x829a ExposureTime | RATIONAL | 1 | 1254 | 1254/0
806 | 0x829d FNumber | RATIONAL | 1 | 1262 | 1262/0
818 | 0x8822 ExposureProgram | SHORT | 1 | 65536 | 1
830 | 0x9000 ExifVersion | UNDEFINED | 4 | 808596016 | 0220
842 | 0x9003 DateTimeOriginal | ASCII | 20 | 1270 | 2004:06:21 23:37:53
854 | 0x9004 DateTimeDigitized | ASCII | 20 | 1290 | 2004:06:21 23:37:53
866 | 0x9101 ComponentsConfiguration | UNDEFINED | 4 | 16909056 | ...
878 | 0x9102 CompressedBitsPerPixel | RATIONAL | 1 | 1310 | 1310/0
890 | 0x9201 ShutterSpeedValue | SRATIONAL | 1 | 1318 | 1318/0
902 | 0x9202 ApertureValue | RATIONAL | 1 | 1326 | 1326/0
914 | 0x9204 ExposureBiasValue | SRATIONAL | 1 | 1334 | 1334/0
926 | 0x9205 MaxApertureValue | RATIONAL | 1 | 1342 | 1342/0
938 | 0x9207 MeteringMode | SHORT | 1 | 131072 | 2
950 | 0x9208 LightSource | SHORT | 1 | 655360 | 10
962 | 0x9209 Flash | SHORT | 1 | 0 | 0
974 | 0x920a FocalLength | RATIONAL | 1 | 1350 | 1350/0
986 | 0x9290 SubSecTime | ASCII | 3 | 808845312 | 06
998 | 0x9291 SubSecTimeOriginal | ASCII | 3 | 808845312 | 06
1010 | 0x9292 SubSecTimeDigitized | ASCII | 3 | 808845312 | 06
1022 | 0xa000 FlashpixVersion | UNDEFINED | 4 | 808529968 | 0100
1034 | 0xa001 ColorSpace | SHORT | 1 |4294901760 | 65535
1046 | 0xa002 PixelXDimension | LONG | 1 | 200 | 200
1058 | 0xa003 PixelYDimension | LONG | 1 | 130 | 130
1070 | 0xa217 SensingMethod | SHORT | 1 | 131072 | 2
1082 | 0xa300 FileSource | UNDEFINED | 1 | 50331648 | .
1094 | 0xa301 SceneType | UNDEFINED | 1 | 16777216 | .
1106 | 0xa401 CustomRendered | SHORT | 1 | 0 | 0
1118 | 0xa402 ExposureMode | SHORT | 1 | 65536 | 1
1130 | 0xa403 WhiteBalance | SHORT | 1 | 65536 | 1
1142 | 0xa404 DigitalZoomRatio | RATIONAL | 1 | 1358 | 1358/0
1154 | 0xa405 FocalLengthIn35mmFilm | SHORT | 1 | 4128768 | 63
1166 | 0xa406 SceneCaptureType | SHORT | 1 | 0 | 0
1178 | 0xa407 GainControl | SHORT | 1 | 0 | 0
1190 | 0xa408 Contrast | SHORT | 1 | 0 | 0
1202 | 0xa409 Saturation | SHORT | 1 | 0 | 0
1214 | 0xa40a Sharpness | SHORT | 1 | 0 | 0
1226 | 0xa40c SubjectDistanceRange | SHORT | 1 | 0 | 0
1238 | 0xa420 ImageUniqueID | ASCII | 33 | 1366 | 127c1377b054a3f65bf2754ebb24e7f2 ...
END MemIo
226 | 0x8825 GPSTag | LONG | 1 | 1400 | 1400
1422 | 0x0103 Compression | SHORT | 1 | 393216 | 6
1434 | 0x011a XResolution | RATIONAL | 1 | 1498 | 1498/0
1446 | 0x011b YResolution | RATIONAL | 1 | 1506 | 1506/0
1458 | 0x0128 ResolutionUnit | SHORT | 1 | 131072 | 2
1470 | 0x0201 JPEGInterchangeFormat | LONG | 1 | 1514 | 1514
1482 | 0x0202 JPEGInterchangeFormatLeng | LONG | 1 | 4196 | 4196
END MemIo
5722 | 0xffed APP13 | 3038 | Photoshop 3.0.8BIM..........Z...
Record | DataSet | Name | Length | Data
1 | 90 | CharacterSet | 3 | .%G
1 | 90 | CharacterSet | 3 | .%G
2 | 0 | RecordVersion | 2 | ..
2 | 120 | Caption | 402 | 040621-N-6536T-062.USS Ronald Reagan (CV...
2 | 122 | Writer | 9 | Dir. NVNS
2 | 40 | SpecialInstructions | 49 | Credit as U.S. Navy photo by Elizabeth T...
2 | 80 | Byline | 32 | Photographer..s Mate 3rd Class (
2 | 85 | BylineTitle | 21 | U.S Navy Photographer
2 | 110 | Credit | 8 | U.S Navy
2 | 115 | Source | 24 | Navy Visual News Service
2 | 5 | ObjectName | 18 | 040621-N-6536T-062
2 | 55 | DateCreated | 8 | 20040621
2 | 60 | TimeCreated | 11 | 000000+0000
2 | 62 | DigitizationDate | 8 | 20040621
2 | 63 | DigitizationTime | 11 | 233753-0400
2 | 90 | City | 19 | Straits of Magellan
2 | 101 | CountryName | 13 | South America
2 | 15 | Category | 1 | N
2 | 20 | SuppCategory | 12 | 703-614-9154
2 | 20 | SuppCategory | 23 | navyvisualnews@navy.mil
2 | 20 | SuppCategory | 11 | UNCLASSFIED
2 | 10 | Urgency | 1 | 5
2 | 25 | Keywords | 13 | ronald reagan
2 | 25 | Keywords | 6 | reagan
2 | 25 | Keywords | 6 | cvn 76
2 | 25 | Keywords | 6 | cvn-76
2 | 25 | Keywords | 18 | straights magellan
2 | 25 | Keywords | 8 | magellan
2 | 25 | Keywords | 7 | carrier
2 | 25 | Keywords | 12 | nimitz-class
2 | 25 | Keywords | 4 | ship
2 | 25 | Keywords | 8 | underway
8762 | 0xffe1 APP1 | 5329 | http://ns.adobe.com/xap/1.0/.<?x
14093 | 0xffe2 APP2 | 576 | ICC_PROFILE......0ADBE....mntrRG chunk 1/1
14671 | 0xffee APP14 | 14 | Adobe.d@......
14687 | 0xffdb DQT | 132
14821 | 0xffc0 SOF0 | 17
14840 | 0xffdd DRI | 4
14846 | 0xffc4 DHT | 418
15266 | 0xffda SOS
544 rmills@rmillsmbp:~/gnu/exiv2/trunk $ </pre>
The Tagged Image File Format is a container. It's very flexible and can deal with multiple pages, different colour spaces, frame configurations as well as metadata. The specification is available from: https://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
!Tiff.png!
The format consists of an 8 byte header which provides a 2 byte endian flag (II or MM), a 2 byte type "magic number" (42) and a 4 byte offset to an _*Image File Directory*_.
The _*IFD*_ _(Image File Directory)_ has a two byte header which contains the length of the directory followed by 12 byte field or "tag". The trailing 4 bytes of the the directory is always the offset to the next dictionary _*or*_ zero to terminate the directory chain.
A tag consists of a 12 byte record: TagID, TagType, Count and Offset which are 2,2,4 and 4 bytes respectively. The TagID defines the purpose of the record (Width, Height, ColorSpace etc) and the TagType defines the data format. Count and Offset are used to contain the raw data _*or*_ provide an offset in the file at which to read the raw data for this tag.
This is described in the specification. The code in tiff image.cpp/ TiffImage::printStructure() decodes the dictionaries.
The TIFF container is so flexible it is used as the structure for most RAW formats including Adobe's DNG. Additionally the TIFF container is used to store the metadata that lies inside the Exif blocks embedded in JPEG and PNG files.
There is a 64bit version of Tiff called _*BigTiff*_. This is currently not supported by exiv2.
*Example:*
The version of exiv2(.exe) which ships with v0.25 provides options _*<code>-pS</code>*_ to reveals the structure of the TIFF and option _*<code>-pX</code>*_ is used to extract the raw XMP/xml data.
The option _*<code>-pa</code>*_ -pa is used to print the metadata in human readable format.<pre>$ exiv2 -pa test/data/test.tiff ~/tif
$ exiv2 -pa test/data/test.tiff
Exif.Image.NewSubfileType Long 1 Primary image
Exif.Image.ImageWidth Short 1 282 40
Exif.Image.ImageLength Short 1 212 470
Exif.Image.BitsPerSample Short 3 8 8 8
Exif.Image.Compression Short 1 LZW
Exif.Image.PhotometricInterpretation Short 1 RGB
Exif.Image.ImageDescription Ascii 32
Exif.Image.Make Ascii 5 SONY
Exif.Image.Model Ascii 9 DSC-S600
Exif.Image.StripOffsets Long 16 1 4372 ... 2694
Exif.Image.Orientation Short 1 top, left right, top
Exif.Image.SamplesPerPixel Short 1 3
Exif.Image.RowsPerStrip Long Short 1 14 1092
Exif.Image.StripByteCounts Long 16 10492 ...
Exif.Image.XResolution Rational 1 96 5086
Exif.Image.YResolution Rational 1 96
Exif.Image.PlanarConfiguration Short 1 1
Exif.Image.ResolutionUnit Short 1 inch
Exif.Image.DateTime Ascii 20 2009:04:26 12:38:18
Exif.Image.Predictor Short 1 No prediction scheme used Horizontal differencing
Exif.Image.SampleFormat Short 3 Unsigned integer data
Exif.Image.XMLPacket Byte 2505 2500 (Binary value suppressed)
Exif.Image.InterColorProfile Undefined 1352 (Binary value suppressed)
Xmp.dc.title LangAlt 1 lang="x-default" this is a test image title
/Users/rmills/tif: (No IPTC data found in the file)
$ exiv2 -pS ~/tif
STRUCTURE OF TIFF FILE (II): test/data/test.tiff FILE: /Users/rmills/tif
address | tag | type | count | offset | value
10 | 0x00fe NewSubfileType | LONG | 1 | 0 | 0
22 | 0x0100 ImageWidth | SHORT | 1 | 282 2621440 | 282 40
34 22 | 0x0101 ImageLength | SHORT | 1 | 212 30801920 | 212 470
46 34 | 0x0102 BitsPerSample | SHORT | 3 | 290 182 | 8 8 8
58
46 | 0x0103 Compression | SHORT | 1 | 5 327680 | 5
70 58 | 0x0106 PhotometricInterpretation PhotometricInterpret | SHORT | 1 | 2 131072 | 2
82 70 | 0x010e ImageDescription | ASCII | 32 | 296 |
94 | 0x010f Make | ASCII | 5 | 328 | SONY
106 | 0x0110 Model | ASCII | 9 | 334 | DSC-S600
118 | 0x0111 StripOffsets | LONG | 16 1 | 344 2694 | 4372 14864 25634 37110 50496 ...
130 0
82 | 0x0112 Orientation | SHORT | 1 | 1 393216 | 1
142 6
94 | 0x0115 SamplesPerPixel | SHORT | 1 | 3 196608 | 3
154 106 | 0x0116 RowsPerStrip | LONG SHORT | 1 | 14 71565312 | 14 1092
166 118 | 0x0117 StripByteCounts | LONG | 16 | 408 | 10492 10770 11476 13385 13348 ...
178 | 0x011a XResolution | RATIONAL | 1 | 472 5086 | 96/1 0
190 130 | 0x011b YResolution | RATIONAL | 1 | 480 | 96/1
202 | 0x011c PlanarConfiguration | SHORT | 1 | 1 65536 | 1
214 142 | 0x0128 ResolutionUnit 0x013d Predictor | SHORT | 1 | 2 131072 | 2
226 154 | 0x0132 DateTime | ASCII | 20 | 488 | 2009:04:26 12:38:18
238 | 0x013d Predictor | SHORT | 1 | 1 | 1
250 | 0x0153 SampleFormat | SHORT | 3 | 508 188 | 1 1 1
262
166 | 0x02bc XMLPacket | BYTE | 2505 2500 | 514 194 | <?xpacket begin="..." id="W5M0Mp ...
274 | 0x8773 InterColorProfile | UNDEFINED | 1352 | 3020 | ...Happl. ..scnrRGB XYZ ....... ...
END test/data/test.tiff
$ exiv2 -pX test/data/test.tiff ~/tif | xmllint --format -pretty 1 -
<?xml version="1.0"?>
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about="">
<dc:title>
<rdf:Alt>
<rdf:li xml:lang="x-default">this is a test image</rdf:li> title</rdf:li>
</rdf:Alt>
</dc:title>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
855 rmills@rmillsmbp:~/Documents/exiv2 $ </pre>You </pre>
You can use the output from _*<code>-pS</code>*_ to determine the location of the XMLPacket:<pre>$ exiv2 -pS --grep XML test/data/test.tiff | grep XMLPacket
262 | 0x02bc XMLPacket | BYTE | 2505 | 514 | <?xpacket begin="..." id="W5M0Mp ...
$ </pre>You can clearly see the XMLPacket of 2505 bytes is stored at offset 514. 194 into the file and consists of 2500 bytes. You can of course directly extract the XMP with the following command which says: set the block size to 1 byte, skip 514 194 bytes and extract 2505 bytes:
<pre>$ dump the next 2500 bytes:<pre>863 rmills@rmillsmbp:~/Documents/exiv2 $ dd bs=1 count=2505 skip=514 if=test/data/test.tiff skip=194 count=2500 if=~/tif | xmllint --format -pretty 1 -
2505+0
2500+0 records in
2505+0 2500+0 records out
2505 2500 bytes (2.5 kB) copied, 0.0064 s, 391 kB/s transferred in 0.005714 secs (437526 bytes/sec)
<?xml version="1.0"?>
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.4.0-Exiv2">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description xmlns:dc="http://purl.org/dc/elements/1.1/" rdf:about="">
<dc:title>
<rdf:Alt>
<rdf:li xml:lang="x-default">this is a test image</rdf:li> title</rdf:li>
</rdf:Alt>
</dc:title>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
864 rmills@rmillsmbp:~/Documents/exiv2 $ </pre>The option _*<code>-pX</code>*_ doesn't actually use dd to achieve the same result and is much more convenient to use.
To demonstrate that the metadata block in a JPEG is a TIFF file, extract and print the structure.<pre>$ exiv2 -pS test/data/Reagan.jpg ~/jpg
$ exiv2 -pS test/data/Reagan.jpg
STRUCTURE OF JPEG FILE: test/data/Reagan.jpg /Users/rmills/jpg
address | marker | length length | data
0 2 | 0xffd8 0xd8 SOI
2 4 | 0xffe1 0xe1 APP1 | 5718 14862 | Exif..MM.*......................
5722 Exif..II*.....................
14868 | 0xffed APP13 | 3038 | Photoshop 3.0.8BIM..........Z...
8762 | 0xffe1 0xe1 APP1 | 5329 2720 | http://ns.adobe.com/xap/1.0/.<?x http://ns.adobe.com/xap/1.0/.<
14093 17590 | 0xffe2 APP2 0xed APP13 | 576 110 | ICC_PROFILE......0ADBE....mntrRG chunk 1/1 Photoshop 3.0.8BIM.......6....
14671 17702 | 0xffee APP14 0xe2 APP2 | 14 4094 | Adobe.d@...... MPF.II*...............0100....
14687 21798 | 0xffdb 0xdb DQT | 132
14821 21932 | 0xffc0 0xc0 SOF0 | 17
14840 21951 | 0xffdd DRI | 4
14846 | 0xffc4 0xc4 DHT | 418
15266 22371 | 0xffda 0xda SOS
| 12
$ </pre> We can extract the APP1/Exif data as follows:<pre>$ dd bs=1 skip=$((2+2+8)) count=$((5718-8)) if=test/data/Reagan.jpg of=ReaganExif.tiff skip=12 count=14862 if=~/jpg of=bull.tif
5710+0 14862+0 records in
5710+0 14862+0 records out
5710 14862 bytes (5.7 kB) copied, 0.026688 s, 214 kB/s transferred in 0.038783 secs (383211 bytes/sec)
$ exiv2 -pS ReaganExif.tif
bull.tif
STRUCTURE OF TIFF FILE (MM): ReaganExif.tif FILE: bull.tif
address | tag | type | count | offset | value
10 | 0x0100 ImageWidth | SHORT | 1 | 13107200 | 200
22 | 0x0101 ImageLength | SHORT | 1 | 8519680 | 130
34 | 0x0102 BitsPerSample | SHORT | 4 | 242 | 8 8 8 8
46 | 0x0103 Compression | SHORT | 1 | 65536 | 1
58 | 0x0106 PhotometricInterpretation | SHORT | 1 | 131072 | 2
70 | 0x010e ImageDescription | ASCII | 403 | 250 | 040621-N-6536T-062.USS Ronald Re ...
82 | 0x010f Make | ASCII | 18 | 653 134 | NIKON CORPORATION CORPORATION.
94 22 | 0x0110 Model | ASCII | 10 12 | 671 152 | NIKON D1X
106 D5300.
34 | 0x0112 Orientation | SHORT | 1 | 65536 | 1
118 | 0x0115 SamplesPerPixel | SHORT | 1
46 | 262144 | 4
130 | 0x011a XResolution | RATIONAL | 1 | 681 164 | 3000000/10000
142
58 | 0x011b YResolution | RATIONAL | 1 | 689 172 | 3000000/10000
154
70 | 0x011c PlanarConfiguration 0x0128 ResolutionUnit | SHORT | 1 | 65536 | 1
166 | 0x0128 ResolutionUnit | SHORT | 1 2 | 131072 | 2
178
82 | 0x0131 Software | ASCII | 40 10 | 697 180 | Adobe Photoshop Elements 12.0 Ma ...
190 Ver.1.00 .
94 | 0x0132 DateTime | ASCII | 20 | 737 190 | 2016:09:13 11:58:16 2015:02:13 20:46:51.
202 106 | 0x013b Artist 0x0213 YCbCrPositioning | ASCII SHORT | 34 1 | 757 1 | Photographer..s Mate 3rd Class ( ... 1
214 118 | 0x8769 ExifTag | LONG | 1 | 792 | 792
226 | 0x8825 GPSTag | LONG 210 | 1 | 1400 | 1400 210
1422 4080 | 0x0103 Compression | SHORT | 1 | 393216 6 | 6
1434 4092 | 0x011a XResolution | RATIONAL | 1 | 1498 4168 | 72/1
1446
4104 | 0x011b YResolution | RATIONAL | 1 | 1506 4176 | 72/1
1458
4116 | 0x0128 ResolutionUnit | SHORT | 1 | 131072 2 | 2
1470 4128 | 0x0201 JPEGInterchangeFormat JPEGInterchangeForma | LONG | 1 | 1514 4184 | 1514 4184
1482 4140 | 0x0202 JPEGInterchangeFormatLeng JPEGInterchangeForma | LONG | 1 | 4196 10670 | 4196 10670
4152 | 0x0213 YCbCrPositioning | SHORT | 1 | 1 | 1
END ReaganExif.tif
$ </pre>The version of the exiv2 command-line program that ships with v0.26 later has an option _*<code>-pR</code>*_ which _*Recursively*_ with recursively prints the structure of an image file. By *_Recursively*_ means *_recursive*_ we mean the utility will print the structures which are embedded within while reside inside other structures. For example, the Exif metadata in a JPEG is a encoded as a TIFF embedded in the file. <pre>$ <pre>543 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -pR test/data/Reagan.jpg
STRUCTURE OF JPEG FILE: test/data/Reagan.jpg
address | marker | length | data
0 | 0xffd8 SOI
2 | 0xffe1 APP1 | 5718 | Exif..MM.*......................
STRUCTURE OF TIFF FILE (MM): MemIo
address | tag | type | count | offset | value
10 | 0x0100 ImageWidth | SHORT | 1 | 13107200 | 200
22 | 0x0101 ImageLength | SHORT | 1 | 8519680 | 130
34 | 0x0102 BitsPerSample | SHORT | 4 | 242 | 8 8 8 8
46 | 0x0103 Compression | SHORT | 1 | 65536 | 1
58 | 0x0106 PhotometricInterpretation | SHORT | 1 | 131072 | 2
70 | 0x010e ImageDescription | ASCII | 403 | 250 | 040621-N-6536T-062.USS Ronald Re ...
82 | 0x010f Make | ASCII | 18 | 653 | NIKON CORPORATION
94 | 0x0110 Model | ASCII | 10 | 671 | NIKON D1X
106 | 0x0112 Orientation | SHORT | 1 | 65536 | 1
118 | 0x0115 SamplesPerPixel | SHORT | 1 | 262144 | 4
130 | 0x011a XResolution | RATIONAL | 1 | 681 | 681/0
142 | 0x011b YResolution | RATIONAL | 1 | 689 | 689/0
154 | 0x011c PlanarConfiguration | SHORT | 1 | 65536 | 1
166 | 0x0128 ResolutionUnit | SHORT | 1 | 131072 | 2
178 | 0x0131 Software | ASCII | 40 | 697 | Adobe Photoshop Elements 12.0 Ma ...
190 | 0x0132 DateTime | ASCII | 20 | 737 | 2016:09:13 11:58:16
202 | 0x013b Artist | ASCII | 34 | 757 | Photographer..s Mate 3rd Class ( ...
214 | 0x8769 ExifTag | LONG | 1 | 792 | 792
STRUCTURE OF TIFF FILE (MM): MemIo
address | tag | type | count | offset | value
794 | 0x829a ExposureTime | RATIONAL | 1 | 1254 | 1254/0
806 | 0x829d FNumber | RATIONAL | 1 | 1262 | 1262/0
818 | 0x8822 ExposureProgram | SHORT | 1 | 65536 | 1
830 | 0x9000 ExifVersion | UNDEFINED | 4 | 808596016 | 0220
842 | 0x9003 DateTimeOriginal | ASCII | 20 | 1270 | 2004:06:21 23:37:53
854 | 0x9004 DateTimeDigitized | ASCII | 20 | 1290 | 2004:06:21 23:37:53
866 | 0x9101 ComponentsConfiguration | UNDEFINED | 4 | 16909056 | ...
878 | 0x9102 CompressedBitsPerPixel | RATIONAL | 1 | 1310 | 1310/0
890 | 0x9201 ShutterSpeedValue | SRATIONAL | 1 | 1318 | 1318/0
902 | 0x9202 ApertureValue | RATIONAL | 1 | 1326 | 1326/0
914 | 0x9204 ExposureBiasValue | SRATIONAL | 1 | 1334 | 1334/0
926 | 0x9205 MaxApertureValue | RATIONAL | 1 | 1342 | 1342/0
938 | 0x9207 MeteringMode | SHORT | 1 | 131072 | 2
950 | 0x9208 LightSource | SHORT | 1 | 655360 | 10
962 | 0x9209 Flash | SHORT | 1 | 0 | 0
974 | 0x920a FocalLength | RATIONAL | 1 | 1350 | 1350/0
986 | 0x9290 SubSecTime | ASCII | 3 | 808845312 | 06
998 | 0x9291 SubSecTimeOriginal | ASCII | 3 | 808845312 | 06
1010 | 0x9292 SubSecTimeDigitized | ASCII | 3 | 808845312 | 06
1022 | 0xa000 FlashpixVersion | UNDEFINED | 4 | 808529968 | 0100
1034 | 0xa001 ColorSpace | SHORT | 1 |4294901760 | 65535
1046 | 0xa002 PixelXDimension | LONG | 1 | 200 | 200
1058 | 0xa003 PixelYDimension | LONG | 1 | 130 | 130
1070 | 0xa217 SensingMethod | SHORT | 1 | 131072 | 2
1082 | 0xa300 FileSource | UNDEFINED | 1 | 50331648 | .
1094 | 0xa301 SceneType | UNDEFINED | 1 | 16777216 | .
1106 | 0xa401 CustomRendered | SHORT | 1 | 0 | 0
1118 | 0xa402 ExposureMode | SHORT | 1 | 65536 | 1
1130 | 0xa403 WhiteBalance | SHORT | 1 | 65536 | 1
1142 | 0xa404 DigitalZoomRatio | RATIONAL | 1 | 1358 | 1358/0
1154 | 0xa405 FocalLengthIn35mmFilm | SHORT | 1 | 4128768 | 63
1166 | 0xa406 SceneCaptureType | SHORT | 1 | 0 | 0
1178 | 0xa407 GainControl | SHORT | 1 | 0 | 0
1190 | 0xa408 Contrast | SHORT | 1 | 0 | 0
1202 | 0xa409 Saturation | SHORT | 1 | 0 | 0
1214 | 0xa40a Sharpness | SHORT | 1 | 0 | 0
1226 | 0xa40c SubjectDistanceRange | SHORT | 1 | 0 | 0
1238 | 0xa420 ImageUniqueID | ASCII | 33 | 1366 | 127c1377b054a3f65bf2754ebb24e7f2 ...
END MemIo
226 | 0x8825 GPSTag | LONG | 1 | 1400 | 1400
1422 | 0x0103 Compression | SHORT | 1 | 393216 | 6
1434 | 0x011a XResolution | RATIONAL | 1 | 1498 | 1498/0
1446 | 0x011b YResolution | RATIONAL | 1 | 1506 | 1506/0
1458 | 0x0128 ResolutionUnit | SHORT | 1 | 131072 | 2
1470 | 0x0201 JPEGInterchangeFormat | LONG | 1 | 1514 | 1514
1482 | 0x0202 JPEGInterchangeFormatLeng | LONG | 1 | 4196 | 4196
END MemIo
5722 | 0xffed APP13 | 3038 | Photoshop 3.0.8BIM..........Z...
Record | DataSet | Name | Length | Data
1 | 90 | CharacterSet | 3 | .%G
1 | 90 | CharacterSet | 3 | .%G
2 | 0 | RecordVersion | 2 | ..
2 | 120 | Caption | 402 | 040621-N-6536T-062.USS Ronald Reagan (CV...
2 | 122 | Writer | 9 | Dir. NVNS
2 | 40 | SpecialInstructions | 49 | Credit as U.S. Navy photo by Elizabeth T...
2 | 80 | Byline | 32 | Photographer..s Mate 3rd Class (
2 | 85 | BylineTitle | 21 | U.S Navy Photographer
2 | 110 | Credit | 8 | U.S Navy
2 | 115 | Source | 24 | Navy Visual News Service
2 | 5 | ObjectName | 18 | 040621-N-6536T-062
2 | 55 | DateCreated | 8 | 20040621
2 | 60 | TimeCreated | 11 | 000000+0000
2 | 62 | DigitizationDate | 8 | 20040621
2 | 63 | DigitizationTime | 11 | 233753-0400
2 | 90 | City | 19 | Straits of Magellan
2 | 101 | CountryName | 13 | South America
2 | 15 | Category | 1 | N
2 | 20 | SuppCategory | 12 | 703-614-9154
2 | 20 | SuppCategory | 23 | navyvisualnews@navy.mil
2 | 20 | SuppCategory | 11 | UNCLASSFIED
2 | 10 | Urgency | 1 | 5
2 | 25 | Keywords | 13 | ronald reagan
2 | 25 | Keywords | 6 | reagan
2 | 25 | Keywords | 6 | cvn 76
2 | 25 | Keywords | 6 | cvn-76
2 | 25 | Keywords | 18 | straights magellan
2 | 25 | Keywords | 8 | magellan
2 | 25 | Keywords | 7 | carrier
2 | 25 | Keywords | 12 | nimitz-class
2 | 25 | Keywords | 4 | ship
2 | 25 | Keywords | 8 | underway
8762 | 0xffe1 APP1 | 5329 | http://ns.adobe.com/xap/1.0/.<?x
14093 | 0xffe2 APP2 | 576 | ICC_PROFILE......0ADBE....mntrRG chunk 1/1
14671 | 0xffee APP14 | 14 | Adobe.d@......
14687 | 0xffdb DQT | 132
14821 | 0xffc0 SOF0 | 17
14840 | 0xffdd DRI | 4
14846 | 0xffc4 DHT | 418
15266 | 0xffda SOS
544 rmills@rmillsmbp:~/gnu/exiv2/trunk $ </pre>