Debian Codegraph @

html/writing.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <title>Writing Meta Information</title>
6 <link rel=stylesheet type='text/css' href='style.css' title='Style'>
7 <style type="text/css">
8 <!--
9 pre { color: #800; margin-left: 4em }
10 -->
11 </style>
12 </head>
13 <body>
14 <div class='index'>
15 <a href="#Abstract">Abstract</a>
16 <br><a href="#Background">Background</a>
17 <br><a href="#Implementation">Current Implementation</a>
18 <br><a href="#Mandatory">Mandatory Tags</a>
19 <br><a href="#JPEG">The JPEG Segment Size Limitation</a>
20 <br><a href="#Preview">The Preview Image Problem</a> (<i>updated 2009-06-12</i>)
21 <br><a href="#IFD0">IFD0/ExifIFD Ambiguity</a>
22 </div>
23 <h1 class='up'>Writing Meta Information</h1>
24 <a name='Abstract'></a>
25 <h3>Abstract</h3>
26 <p>Writing meta information is more complicated than it may appear at first
27 glance, which may be one reason why there are very few utilities around that do
28 it. ExifTool uses tag names to identify the different pieces of meta information
29 that can be extracted from a file. There are thousands of different tags that
30 ExifTool recognizes, and many of these tag names are common between different
31 metadata formats (the WhiteBalance tag is the worst offender, and can be found
32 in 65 different places [ExifTool 10.64]), and sometimes the information can even
33 be stored in different places within a single format. Couple this with the fact
34 that many manufacturers store meta information in undocumented formats which
35 must be reverse engineered (and each of which have their particular quirks), and
36 you have a very complex situation.</p>
37
38 <p>ExifTool attempts to simplify this situation as much as possible by making
39 reasonable decisions about where to write the information you specify, yet it
40 maintains flexibility by allowing you to configure its priorities if necessary,
41 or even override the decision making process entirely.</p>
42
43 <a name='Background'></a>
44 <h3>Background</h3>
45 <p>For a long time, I resisted adding write abilities to ExifTool even though it
46 was an oft-requested feature. My concerns in adding this feature were:</p>
47 <ol>
48 <li>It would complicate the ExifTool interface and make it too confusing for
49 typical users.</li>
50 <li>It would complicate the code enough to slow down processing for normal use.</li>
51 <li>It would take a LOT of work to implement.</li>
52 </ol>
53 <p>After thinking about this for a while, I was finally able to come up with some
54 solutions:</p>
55
56 <p>1. I designed an interface that I think is easy to use for people who
57 don't want to know the details of the file structure, yet powerful enough for
58 people who want to do very specific things to the information.</p>
59
60 <p>2. I isolated all of the writing code as much as possible into separate files
61 which autoload as required. This keeps the compilation fast for people who
62 don't require the write feature. Also, I have left the reading routines
63 unchanged, so they aren't slowed down by the extra code needed when writing
64 information. Unfortunately, this meant I couldn't borrow a lot of code from the
65 read routines (even more work for me!), but it had the advantage that I could
66 perform additional optimizations in the write routines that I couldn't do
67 otherwise. Although the startup costs of this implementation are fairly high
68 (for writing only), it should be quite fast for batch writing of multiple files.</p>
69
70 <p>3. I decided to bite the bullet and invest the time required (...guess what I
71 did for my Christmas vacation!). Although I thought that a big project like
72 this would be better suited to C++ (faster execution and a broader potential
73 user base), after programming this so far in Perl I have grown to really
74 appreciate the automatic memory handling and other great features of Perl such
75 as hash lookups and incredible flexibility in text manipulations afforded by
76 regular expressions.</p>
77
78 <a name='Implementation'></a>
79 <h3>Current Implementation</h3>
80 <p>Currently, ExifTool can write most of the EXIF tags that anyone could reasonably
81 want to change (but some tags are protected because they describe physical
82 characteristics of the image that you can not change with ExifTool, eg.
83 Compression). Also, all of the GPS, IPTC and XMP information and most of the
84 MakerNotes information can be edited. This gives you great power, but with
85 great power, comes great responsibility...</p>
86
87 <p>It is possible for you to write nonsense into a file, which could cause other
88 image readers to throw up their hands in despair and refuse to read the image.
89 For this reason, it is best to always preserve the original copy of your image
90 file. The "exiftool" script does this for you automatically by renaming the
91 original file and always working on a copy.</p>
92
93 <p>The writing logic for ExifTool is the reverse of the reading logic. You
94 provide human-readable values and ExifTool will perform the conversions for you.
95 For instance, you can set "WhiteBalance" to "Daylight" and ExifTool will change
96 the value of WhiteBalance in the image wherever the tag is found provided that
97 "Daylight" is a valid value for that location. ExifTool will even do some simple
98 matching so that you could even just set it to "day", and ExifTool will search
99 through the valid values and will choose the one that contains the string "day".
100 If the value is ambiguous, the tag will not be set. If no tags can be set with
101 the specified value, ExifTool returns an error message.</p>
102
103 <p>The tag values can also be specified at a numerical level by disabling the
104 print conversions that are normally applied. This can be done on a tag-by-tag
105 basis or on a global basis through either the application or the API.</p>
106
107 <p>As well as changing tag values wherever they are found in the image, exiftool
108 will also create the tag in the preferred group if it didn't exist there before.
109 By default, the preferred group is the first of the following where the tag is
110 found: 1) EXIF, 2) IPTC, 3) XMP. Alternatively, the desired group (in family 0
111 or 1) can be specified so ExifTool only writes the tag to a single location. For
112 example, with the command line interface, this is done using an argument like
113 "<code>-EXIF:WhiteBalance=Manual</code>".</p>
114
115 <p>If a tag is added to a group that doesn't exist, the new group is created in
116 the file, and required mandatory tags may be created. Conversely, if the last
117 non-mandatory tag is deleted from a group, the group is removed from the file.</p>
118
119 <a name='Mandatory'></a>
120 <h3>Mandatory Tags</h3>
121
122 <p>The EXIF and IPTC standards both specify some mandatory tags. ExifTool will
123 automatically create many of these mandatory tags as required when writing new
124 information (and remove them again when deleting information if only mandatory
125 tags remain). However, some mandatory tags (particularly in the IPTC
126 information) can not be easily added automatically, so it is left up to the user
127 to add these tags if required. Note that ExifTool 12.71 adds an API
128 <a href="ExifTool.html#NoMandatory">NoMandatory</a> option which bypasses
129 the creation/deletion of mandatory tags in EXIF when writing.</p>
130
131 <blockquote class='aside'>
132 <b>Rant:</b> Let me say that the whole concept of mandatory tags is flawed.
133 Instead of mandatory tags, the standard should specify default values to be
134 assumed if the tags don't exist. A robust reader has to do this anyway, so it
135 is redundant to require that this information must be written. In the case
136 where there is no simple default value, the reader must be able to deal with the
137 missing tag, otherwise it places the burden on the writer to magically pull a
138 reasonable value out of thin air. Of course, you may say that the writer could
139 get this information from the user, but conditions like this add an unnecessary
140 level complexity to the user interface.
141 </blockquote>
142
143 <p><b>2025-03-03</b>: To make matters worse, some EXIF tags which were
144 previously listed as mandatory have been changed to optional under the EXIF 3.0
145 specification. Introducing a version dependency only complicates the situation.
146 ExifTool 13.23 and later will simplify this problem by treating these newly
147 re-categorized tags as optional for all EXIF versions.</p>
148
149 <a name='JPEG'></a>
150 <h3>The JPEG Segment Size Limitation</h3>
151
152 <p>An unfortunate aspect of the JPEG format is that the size of a single segment
153 is limited to less than 64 kB. With the 2-byte size word at the start of each
154 segment, this leaves 65533 bytes for data. The EXIF specification states that
155 the data must fit within a single <b>APP1</b> segment (which results in the
156 preview image problem discussed below), however <b>APP13</b> Photoshop and
157 <b>APP2</b> ICC Profile and FPXR information may span multiple segments. This
158 multi-segment information is handled properly by ExifTool.</p>
159
160 <p>JPEG comments may also exceed the size of a single <b>COM</b> segment. If
161 necessary, comments are automatically split into separate segments when writing.
162 However, when reading they are not joined together because some utilities store
163 distinctly different comments in separate segments. To extract all JPEG
164 comments into a single file, and combine any comments that may have been split
165 into multiple segments, use "<code>exiftool -a -b -comment src.jpg &gt;
166 comment.out</code>".</p>
167
168 <a name='Preview'></a>
169 <h3>The Preview Image Problem</h3>
170
171 <p>Writing the preview image in JPEG files poses many problems of its own. These
172 problems stem from the fact that the JPEG standard is inadequate for storing
173 large preview images due to the 64kB limit on segment size as mentioned above.
174 (Note that TIFF images don't have this problem since they have a 4GB limit.)
175 Some manufacturers get around this by appending the preview after the normal end
176 of the JPEG file (JPEG EOI), but this causes complications because it means that
177 the preview image pointers in the EXIF information now point outside the EXIF
178 segment. This is truly unfortunate because it greatly complicates things for
179 image writing software. Most other software can't deal with a preview image and
180 will simply remove a preview like this when rewriting the file.</p>
181
182 <p>However, as of ExifTool version 5, the preview images are handled properly
183 when writing EXIF information in JPEG files. But for reasons of efficiency, the
184 EXIF segment is not edited when writing information if no EXIF tags are being
185 changed (eg. if only XMP or IPTC information is being edited). In this case,
186 the preview image pointers could be invalidated because the length of the data
187 between the EXIF segment (which comes near the start of the file) and the
188 preview image (at the end of the file) is likely to change. ExifTool gets
189 around this when reading JPEG images by looking for the preview at the end of
190 the file and updating pointers if necessary, but the preview image may not be
191 readable by other software (it should be noted though that very few image
192 readers even know the preview image exists). However, the preview pointers in
193 such a file can be fixed if necessary by simply using ExifTool to edit any EXIF
194 information.</p>
195
196 <p><b>2009-05-26</b>: New Samsung cameras recently started embedding preview
197 images larger than 64 kB, and of course they created a new technique to do so.
198 If they were smart, they would have developed a simple technique that could be
199 used by others in the future, but of course they were stupid, and didn't think
200 that far ahead. (Such is the normal path of dumb camera manufacturers when it
201 comes to metadata.)</p>
202
203 <p>The new Samsung models simply split the preview and write it to separate APP2
204 segments with no header. If they had written a header (like "PREVIEW\0" for
205 example), then the technique could be portable and useful. But they didn't.
206 Without a header, the data can not easily be distinguished from other random APP2
207 data, so this technique is not generally useful. Of course, there are
208 disadvantages with splitting up a preview into separate JPEG segments, so this
209 technique in general is not ideal.</p>
210
211 <p><b>2009-06-12</b>:
212 <a href="http://www.cipa.jp/std/std-sec_e.html">CIPA</a>
213 has recently released a "<b>Multi-Picture Format</b>" standard for storing large
214 images in JPEG files. Again, there is a big problem with this standard: It
215 uses offsets that are relative to the start of the MPF header (in the new MPF
216 APP2 segment) to reference images after the JPEG EOI. These offsets will
217 quickly be broken if any data after the MPF segment changes length. This
218 problem could have been avoided if offsets had been specified relative to the
219 end of file, but it is too late for this now that the specification is
220 public.</p>
221
222 <p>The only workable alternative I can see is to enforce the rule that the MPF
223 APP2 segment must come after all other APP segments. (It would have been smart
224 if this was specified in the CIPA standard, but sadly this isn't the case.) If
225 this is done, then metadata in the remaining APP segments (EXIF, IPTC, XMP, etc)
226 can safely be edited without breaking the MPF offsets. I suggest that all
227 metadata editors employ this strategy, regardless of the segment order specified
228 in the standard (which says that the MPF APP2 segment must come immediately
229 after the EXIF APP1 segment).</p>
230
231 <a name='IFD0'></a>
232 <h3>IFD0/ExifIFD Ambiguity</h3>
233
234 <p>ExifTool has a preferred location (IFD) where it writes all EXIF tags.
235 However, a number of tags are written to different locations by various digital
236 cameras or image editors. Specifically, the following tags have been observed
237 in both IFD0 and ExifIFD: Make, Model, Software, Artist, DateTimeOriginal,
238 SensingMethod, CustomRendered, ExposureMode, WhiteBalance, DigitalZoomRatio and
239 SceneCaptureType. To handle this ambiguity, ExifTool will delete the tag if it
240 exists in IFD0 when it is written to ExifIFD, and vice versa.</p>
241
242 <hr>
243 <i>Created Dec 30, 2004</i><br>
244 <i>Last revised Mar 3, 2025</i>
245 <p class='lf'><a href="index.html">&lt;-- Back to ExifTool home page</a></p>
246 </body>
247 </html>