Project

General

Profile

Actions

The Metadata in TIFF files » History » Revision 1

Revision 1/20 | Next »
Robin Mills, 26 Apr 2015 16:46


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

The format is quite simple and consists of a fixed format header (of 8 bytes) which provides the offset of a directory of records. A directory has a two byte header which contains the length of the directory followed by 12 byte records or "tags". The final entry in the directory is always the offset to the next dictionary. A dictionary of length == 0 terminates the directory chain.

A tag consists of a 12 byte record: Tag, Type, Count, Offset which are 2,2,4 and 4 bytes respectively. The Tag defines the purpose of the record (Width, Height, ColorSpace etc) and the Type defines the nature of the data. Count and Offset are used to contain the data, or provide an offset in the file at which to read the raw data for this tag.

This is all very well 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 contain is used to store the metadata that lies inside the Exif and Iptc data blocks within JPEG and PNG files.

Example:
The version of exiv2(.exe) which ships with v0.25 provides options -pS to reveal the structure of the TIFF and option -pX is used to extract the raw XMP/xml data. The option -pa is used to print the metadata in human readable format.

$ exiv2 -pa ~/tif
Exif.Image.ImageWidth                        Short       1  40
Exif.Image.ImageLength                       Short       1  470
Exif.Image.BitsPerSample                     Short       3  8 8 8
Exif.Image.Compression                       Short       1  LZW
Exif.Image.PhotometricInterpretation         Short       1  RGB
Exif.Image.StripOffsets                      Long        1  2694
Exif.Image.Orientation                       Short       1  right, top
Exif.Image.SamplesPerPixel                   Short       1  3
Exif.Image.RowsPerStrip                      Short       1  1092
Exif.Image.StripByteCounts                   Long        1  5086
Exif.Image.PlanarConfiguration               Short       1  1
Exif.Image.Predictor                         Short       1  Horizontal differencing
Exif.Image.SampleFormat                      Short       3  Unsigned integer data
Exif.Image.XMLPacket                         Byte      2500  (Binary value suppressed)
Xmp.dc.title                                 LangAlt     1  lang="x-default" this is a title
/Users/rmills/tif: (No IPTC data found in the file)
$ exiv2 -pS ~/tif
STRUCTURE OF TIFF FILE: /Users/rmills/tif
 address |    tag                      |      type |    count |   offset | value
      10 | 0x0100 ImageWidth           |     SHORT |        1 |  2621440 | 40
      22 | 0x0101 ImageLength          |     SHORT |        1 | 30801920 | 470
      34 | 0x0102 BitsPerSample        |     SHORT |        3 |      182 | 
      46 | 0x0103 Compression          |     SHORT |        1 |   327680 | 5
      58 | 0x0106 PhotometricInterpret |     SHORT |        1 |   131072 | 2
      70 | 0x0111 StripOffsets         |      LONG |        1 |     2694 | 0
      82 | 0x0112 Orientation          |     SHORT |        1 |   393216 | 6
      94 | 0x0115 SamplesPerPixel      |     SHORT |        1 |   196608 | 3
     106 | 0x0116 RowsPerStrip         |     SHORT |        1 | 71565312 | 1092
     118 | 0x0117 StripByteCounts      |      LONG |        1 |     5086 | 0
     130 | 0x011c PlanarConfiguration  |     SHORT |        1 |    65536 | 1
     142 | 0x013d Predictor            |     SHORT |        1 |   131072 | 2
     154 | 0x0153 SampleFormat         |     SHORT |        3 |      188 | 
     166 | 0x02bc XMLPacket            |      BYTE |     2500 |      194 | <?xpacket begin="..." id="W5M0Mp ...
$ exiv2 -pX ~/tif | xmllint -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 title</rdf:li>
        </rdf:Alt>
      </dc:title>
    </rdf:Description>
  </rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
855 rmills@rmillsmbp:~/Documents/exiv2 $ 

You can clearly see the XMLPacket is stored at offset 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, ship 194 bytes and dump the next 2500 bytes:

863 rmills@rmillsmbp:~/Documents/exiv2 $ dd bs=1 skip=194 count=2500 if=~/tif  | xmllint -pretty 1 -
2500+0 records in
2500+0 records out
2500 bytes 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 title</rdf:li>
        </rdf:Alt>
      </dc:title>
    </rdf:Description>
  </rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
864 rmills@rmillsmbp:~/Documents/exiv2 $ 
The option -pX doesn't actually use dd to achieve the same result and is much more convenient to use.

Updated by Robin Mills about 4 years ago · 1 revisions