The Metadata in PNG files » History » Version 10
Tuan Nhu, 15 Aug 2013 07:21
1 | 1 | Tuan Nhu | h1. The Metadata in PNG files |
---|---|---|---|
2 | |||
3 | The Portable Network Graphics (PNG) is a raster graphics file format that supports a portable, legally unencumbered, well-compressed, well-specified standard for lossless bitmapped image files. |
||
4 | |||
5 | A PNG always starts with an 8-byte signature: 137 80 78 71 13 10 26 10 (decimal values). The remainder of the file consists a series of chunks beginning with an IHDR chunk and ending with an IEND chunk. |
||
6 | 2 | Tuan Nhu | |
7 | 6 | Tuan Nhu | h3. 1. Chunks |
8 | 3 | Tuan Nhu | |
9 | Each chunk consists of four parts: |
||
10 | |||
11 | 8 | Tuan Nhu | |_.Length | 4 bytes |An unsigned integer giving the number of bytes in the chunk's data field. The length counts only the data field, not itself, the chunk type code, or the CRC. Zero is a valid length. Although encoders and decoders should treat the length as unsigned, its value must not exceed 2^31-1 bytes. | |
12 | 5 | Tuan Nhu | |_.Chunk type | 4 bytes |Type codes are restricted to consist of uppercase and lowercase ASCII letters and they are case sensitive. |
13 | 7 | Tuan Nhu | + The case of the first letter indicates whether the chunk is critical or not. If the first letter is uppercase, the chunk is critical; if not, the chunk is ancillary (more details are mentioned below). |
14 | 5 | Tuan Nhu | + The case of the second letter indicates whether the chunk is "public" (either in the specification or the registry of special-purpose public chunks) or "private" (not standardised). Uppercase is public and lowercase is private. |
15 | + The third letter must be uppercase to conform to the PNG specification. It is reserved for future expansion. |
||
16 | 1 | Tuan Nhu | + The case of the fourth letter indicates whether the chunk is safe to copy by editors that do not recognize it.| |
17 | |_.Chunk data| _Length_ bytes |The data bytes appropriate to the chunk type, if any. This field can be of zero length. | |
||
18 | |_.CRC| 4 bytes| A CRC (Cyclic Redundancy Check) calculated on the preceding bytes in the chunk, including the chunk type code and chunk data fields, but not including the length field. The CRC is always present, even for chunks containing no data. | |
||
19 | 6 | Tuan Nhu | |
20 | 7 | Tuan Nhu | p=. _Fig.1. The chunk layout._ |
21 | 1 | Tuan Nhu | |
22 | 10 | Tuan Nhu | Chunks declare themselves as _critical_ or _ancillary_. Chunks that are necessary for successful display of the file's contents are called _critical_ chunks. If a decoder encounters a critical chunk it does not recognize, it must abort reading the file or supply the user with an appropriate warning. |
23 | 7 | Tuan Nhu | |
24 | 10 | Tuan Nhu | |_.Name |_.Multiple |_.Ordering constraints|_.Content | |
25 | 7 | Tuan Nhu | |IHDR | No |Must be the first |the image's width, height, and bit depth| |
26 | |PLTE | No |Before IDAT |the palette; list of colors.| |
||
27 | |IDAT | Yes |Multiple IDATs must be consecutive |the actual image data, which may be split among multiple IDAT chunks. Such splitting increases filesize slightly, but makes it possible to generate a PNG in a streaming manner. | |
||
28 | |IEND | No |Must be the last |it just marks the image end. The chunk's data field is empty. | |
||
29 | |||
30 | 1 | Tuan Nhu | p=. _Fig.2. Some standard critical chunks._ |
31 | 7 | Tuan Nhu | |
32 | Chunks that are not strictly necessary in order to meaningfully display the contents of the file are known as _ancillary_ chunks. It includes gamma values, background color, and textual metadata information, ect... If a decoder encourters an ancillary chunk that it does not understand can safely ignore it. |
||
33 | 1 | Tuan Nhu | |
34 | 10 | Tuan Nhu | |_.Name |_.Multiple |_.Ordering constraints|_.Content | |
35 | 7 | Tuan Nhu | |cHRM |No |Before PLTE and IDAT |the chromaticity coordinates of the display primaries and white point.| |
36 | |gAMA |No |Before PLTE and IDAT |gamma values.| |
||
37 | |iCCP |No |Before PLTE and IDAT |an ICC color profile.| |
||
38 | 10 | Tuan Nhu | |sBIT |No |Before PLTE and IDAT |the color-accuracy of the source data.| |
39 | |sRGB |No |Before PLTE and IDAT |the standard sRGB color space.| |
||
40 | |bKGD |No |After PLTE; before IDAT|the default background color. It is intended for use when there is no better choice available, such as in standalone image viewers.| |
||
41 | 7 | Tuan Nhu | |hIST |No |After PLTE; before IDAT|the histogram, or total amount of each color in the image.| |
42 | |tRNS |No |After PLTE; before IDAT|transparency information.For indexed images, it stores alpha channel values for one or more palette entries. For truecolor and grayscale images, it stores a single pixel value that is to be regarded as fully transparent.| |
||
43 | |pHYs |No |Before IDAT |the intended pixel size and/or aspect ratio of the image.| |
||
44 | |sPLT |Yes |Before IDAT |a palette to use if the full range of colors is unavailable.| |
||
45 | |tIME |No |None |the time that the image was last changed.| |
||
46 | 9 | Tuan Nhu | |iTXt |Yes |None |UTF-8 text, compressed or not, with an optional language tag.| |
47 | |tEXt |Yes |None |text that can be represented in ISO/IEC 8859-1.| |
||
48 | 7 | Tuan Nhu | |zTXt |Yes |None |compressed text with the same limits as tEXt. | |
49 | |||
50 | p=. _Fig.3. Some standard ancillary chunks._ |
||
51 | 1 | Tuan Nhu | |
52 | h3. 2. Textual information chunks - the metadata in PNG |
||
53 | 9 | Tuan Nhu | |
54 | The iTXt, tEXt, and zTXt chunks (text chunks) are used for conveying textual information associated with the image. They are the places we can find all metadata of PNG file. |
||
55 | |||
56 | Each of the text chunks contains as its first field a keyword that indicates the type of information represented by the text string. The following keywords are predefined and should be used where appropriate: |
||
57 | |_.Keywords |_.Explain | |
||
58 | |Title |Short (one line) title or caption for image | |
||
59 | |Author |Name of image's creator | |
||
60 | |Description |Description of image (possibly long) | |
||
61 | 1 | Tuan Nhu | |Copyright |Copyright notice | |
62 | 9 | Tuan Nhu | |Creation Time |Time of original image creation | |
63 | |Software |Software used to create the image | |
||
64 | |Disclaimer |Legal disclaimer | |
||
65 | |Warning |Warning of nature of content | |
||
66 | |Source |Device used to create the image | |
||
67 | |Comment |Miscellaneous comment; conversion from GIF comment| |
||
68 | |||
69 | 10 | Tuan Nhu | Other keywords may be invented for other purposes and they can be used to embed Exif, IPTC, and XMP data in PNG. The keyword must be at least one character and less than 80 characters long. |
70 | 9 | Tuan Nhu | |
71 | h4. 2.1 tEXt Textual data |
||
72 | |||
73 | In the format: |
||
74 | |||
75 | |_.Keyword |_.Null separator |_.Text| |
||
76 | |1-79 bytes|1 byte | n bytes | |
||
77 | |||
78 | 1 | Tuan Nhu | The text is interpreted according to the ISO/IEC 8859-1 (Latin-1) character set. The text string can contain any Latin-1 character. Newlines in the text string should be represented by a single linefeed character (decimal 10). |
79 | 9 | Tuan Nhu | |
80 | h4. 2.2 zTXt Compressed textual data |
||
81 | |||
82 | In the format: |
||
83 | |||
84 | |_.Keyword |_.Null separator |_.Compression method |_.Compressed text| |
||
85 | |1-79 bytes|1 byte |1 byte | n bytes| |
||
86 | |||
87 | 10 | Tuan Nhu | The zTXt chunk contains textual data, just as tEXt does; however, zTXt takes advantage of compression. The zTXt and tEXt chunks are semantically equivalent, but zTXt is recommended for storing large blocks of text. The only presently legitimate value for _Compression method_ is 0 ("deflate/inflate compression":http://www.w3.org/TR/PNG-Compression.html) |
88 | 9 | Tuan Nhu | |
89 | h4. 2.3 iTXt International textual data |
||
90 | |||
91 | In the format: |
||
92 | |||
93 | |_.Keyword |_.Null separator |_.Compression flag |_.Compression method |_.Language tag |_.Null separator |_.Translated keyword |_.Null separator |_.Text| |
||
94 | |1-79 bytes|1 byte |1 byte | 1 byte| 0 or more bytes |1 byte |0 or more bytes | 1 byte | 0 or more bytes | |
||
95 | |||
96 | This chunk is semantically equivalent to the tEXt and zTXt chunks, but the textual data is in the UTF-8 encoding of the Unicode character set instead of Latin-1 |