-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathexif-read-data.xml
371 lines (363 loc) · 12.5 KB
/
exif-read-data.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: f57352dd7a678230f929e1bac0d4a9189631cf16 Maintainer: jhdxr Status: ready -->
<!-- CREDITS: Luffy -->
<refentry xml:id="function.exif-read-data" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>exif_read_data</refname>
<refpurpose>从一个图片文件中读取 <acronym>EXIF</acronym> 头信息</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>array</type><type>false</type></type><methodname>exif_read_data</methodname>
<methodparam><type class="union"><type>resource</type><type>string</type></type><parameter>file</parameter></methodparam>
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>required_sections</parameter><initializer>&null;</initializer></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>as_arrays</parameter><initializer>&false;</initializer></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>read_thumbnail</parameter><initializer>&false;</initializer></methodparam>
</methodsynopsis>
<para>
<function>exif_read_data</function> 函数从一个图片文件中读取
<acronym>EXIF</acronym> 头信息。这样就可以读取数码相机产生的元数据。
</para>
<para>
<acronym>EXIF</acronym> 头信息往往存在于数码相机生成的 JPEG/TIFF
图片中,但不幸的是每个数码相机制造商的标记都不同,因此(编写代码时)不能依赖于某个特定的
Exif 头信息。
</para>
<para>
<literal>Height</literal> 和 <literal>Width</literal> 是用和 <function>getimagesize</function>
一样的方法计算的,因此它们的值不能是任何返回的头信息的部分。此外
<literal>html</literal> 是一个可以用于普通的 <acronym>HTML</acronym> 中的 height/width 的文本字符串。
</para>
<para>
当一个 Exif 头信息包含有一个 Copyright 时注意它本身可以包含两个值。解决方案和
Exif 2.10 标准不一致,<literal>COMPUTED</literal> 区段会同时返回
<literal>Copyright.Photographer</literal> 和
<literal>Copyright.Editor</literal>,但是 <literal>IFD0</literal>
区段则包含有一个字节数组用 NULL 字符分隔开两个项目。或者只有第一项如果数据类型错误的话(Exif
的正常行为)。<literal>COMPUTED</literal> 也会包含
<literal>Copyright</literal>,要么是原始的版权字符串,要么是逗号分隔的摄像与编辑的版权信息。
</para>
<para>
<literal>UserComment</literal> 标记和 Copyright
有同样的问题。它也可以存储两个值,第一个是使用的编码方式,第二个是其值本身。如果这样则
<literal>IFD</literal> 区段仅包含编码方式或者一个字节数组。<literal>COMPUTED</literal>
区段将存储两个值到 <literal>UserCommentEncoding</literal> 和
<literal>UserComment</literal>。<literal>UserComment</literal>
在两种情况下都可用因此应该优先使用它而不是 <literal>IFD0</literal> 区段中的该值。
</para>
<para>
<function>exif_read_data</function> 还会根据 EXIF
规范(<link
xlink:href="&url.exifspec;">&url.exifspec;</link>,第
20 页)来验证 EXIF 数据。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>file</parameter></term>
<listitem>
<para>
图片文件的位置。这可以是一个文件路径(和往常一样,流封装也是支持的),
或者是一个流式资源(stream <type>resource</type>)。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>required_sections</parameter></term>
<listitem>
<para>
是需要存在于文件中的逗号分隔的区段列表用来产生结果数组。如果未找到所请求的区段则返回值为
&false;。
<informaltable>
<tgroup cols="2">
<tbody>
<row>
<entry>FILE</entry>
<entry>FileName, FileSize, FileDateTime, SectionsFound</entry>
</row>
<row>
<entry>COMPUTED</entry>
<entry>
html,Width,Height,IsColor,可能有更多其它的。Height
和 Width 是用和 <function>getimagesize</function>
一样的方法计算的,因此它们的值不能是任何返回的头信息的部分。此外
<literal>html</literal> 是一个可以用于普通的 <acronym>HTML</acronym> 中的 height/width 的文本字符串。
</entry>
</row>
<row>
<entry>ANY_TAG</entry>
<entry>任何包含有标记的信息,例如 <literal>IFD0</literal>,<literal>EXIF</literal>,...</entry>
</row>
<row>
<entry>IFD0</entry>
<entry>
所有 IFD0 的标记数据。在标准的图像文件中这包含了图像大小及其它。
</entry>
</row>
<row>
<entry>THUMBNAIL</entry>
<entry>
如果有第二个 <literal>IFD</literal>,文件应该包含有缩略图。所有有关嵌入缩略图的标记信息都存储在本区。
</entry>
</row>
<row>
<entry>COMMENT</entry>
<entry>JPEG 图像的注释头信息。</entry>
</row>
<row>
<entry>EXIF</entry>
<entry>
EXIF 区段是 <literal>IFD0</literal> 的子区,包含有图像的更多详细信息。大多数内容都是数码相机相关的。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>as_arrays</parameter></term>
<listitem>
<para>
指定了是否每个区段都成为一个数组。<parameter>required_sections</parameter>
<literal>COMPUTED</literal>,<literal>THUMBNAIL</literal>
和<literal>COMMENT</literal>
区段总是成为数组,因为它们里面包含的名字和其它区段冲突。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>read_thumbnail</parameter></term>
<listitem>
<para>
当设定为 &true; 时,读取缩略图本身。否则只读取标记数据。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
返回一个关联数组,键名是头信息名,值为与其相应的值。如果没有可供返回的数据,<function>exif_read_data</function>
将返回 &false;。
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
当遇到不支持的标签,或其他潜在的错误情况时,将抛出<constant>E_WARNING</constant>
与<constant>E_NOTICE</constant>等级的错误,但这个函数依然会尝试去读取所有可理解的信息。
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
<parameter>required_sections</parameter> 现在可以为空。
</entry>
</row>
<row>
<entry>7.2.0</entry>
<entry>
<parameter>file</parameter> 参数现在起支持本地文件和流式资源。
</entry>
</row>
<row>
<entry>7.2.0</entry>
<entry>
<para>
新增了以下 EXIF 格式的支持:
<simplelist>
<member>Samsung</member>
<member>DJI</member>
<member>Panasonic</member>
<member>Sony</member>
<member>Pentax</member>
<member>Minolta</member>
<member>Sigma/Foveon</member>
<member>AGFA</member>
<member>Kyocera</member>
<member>Ricoh</member>
<member>Epson</member>
</simplelist>
</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>exif_read_data</function> 例子</title>
<programlisting role="php">
<![CDATA[
<?php
echo "test1.jpg:<br />\n";
$exif = exif_read_data('tests/test1.jpg', 'IFD0');
echo $exif===false ? "No header data found.<br />\n" : "Image contains headers<br />\n";
$exif = exif_read_data('tests/test2.jpg', 0, true);
echo "test2.jpg:<br />\n";
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
echo "$key.$name: $val<br />\n";
}
}
?>
]]>
</programlisting>
<para>
第一个调用失败了,因为图像没有头信息。
</para>
&example.outputs.similar;
<screen role="php">
<![CDATA[
test1.jpg:
No header data found.
test2.jpg:
FILE.FileName: test2.jpg
FILE.FileDateTime: 1017666176
FILE.FileSize: 1240
FILE.FileType: 2
FILE.SectionsFound: ANY_TAG, IFD0, THUMBNAIL, COMMENT
COMPUTED.html: width="1" height="1"
COMPUTED.Height: 1
COMPUTED.Width: 1
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 1
COMPUTED.UserComment: Exif test image.
COMPUTED.UserCommentEncoding: ASCII
COMPUTED.Copyright: Photo (c) M.Boerger, Edited by M.Boerger.
COMPUTED.Copyright.Photographer: Photo (c) M.Boerger
COMPUTED.Copyright.Editor: Edited by M.Boerger.
IFD0.Copyright: Photo (c) M.Boerger
IFD0.UserComment: ASCII
THUMBNAIL.JPEGInterchangeFormat: 134
THUMBNAIL.JPEGInterchangeFormatLength: 523
COMMENT.0: Comment #1.
COMMENT.1: Comment #2.
COMMENT.2: Comment #3end
THUMBNAIL.JPEGInterchangeFormat: 134
THUMBNAIL.Thumbnail.Height: 1
THUMBNAIL.Thumbnail.Height: 1
]]>
</screen>
</example>
</para>
<para>
<example>
<title><function>exif_read_data</function> with streams available as of PHP 7.2.0</title>
<programlisting role="php">
<![CDATA[
<?php
// Open a the file, this should be in binary mode
$fp = fopen('/path/to/image.jpg', 'rb');
if (!$fp) {
echo 'Error: Unable to open image for reading';
exit;
}
// Attempt to read the exif headers
$headers = exif_read_data($fp);
if (!$headers) {
echo 'Error: Unable to read exif headers';
exit;
}
// Print the 'COMPUTED' headers
echo 'EXIF Headers:' . PHP_EOL;
foreach ($headers['COMPUTED'] as $header => $value) {
printf(' %s => %s%s', $header, $value, PHP_EOL);
}
?>
]]>
</programlisting>
&example.outputs.similar;
<screen role="php">
<![CDATA[
EXIF Headers:
Height => 576
Width => 1024
IsColor => 1
ByteOrderMotorola => 0
ApertureFNumber => f/5.6
UserComment =>
UserCommentEncoding => UNDEFINED
Copyright => Denis
Thumbnail.FileType => 2
Thumbnail.MimeType => image/jpeg
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<para>
If <link linkend="ref.mbstring">mbstring</link> is enabled, exif will attempt to process
the unicode and pick a charset as specified by
<link linkend="ini.exif.decode-unicode-motorola">exif.decode_unicode_motorola</link> and
<link linkend="ini.exif.decode-unicode-intel">exif.decode_unicode_intel</link>. The exif
extension will not attempt to figure out the encoding on its own, and it is up to the user
to properly specify the encoding for which to use for decoding by setting one of these two
ini directives prior to calling <function>exif_read_data</function>.
</para>
</note>
<note>
<para>
If the <parameter>file</parameter> is used to pass a stream to this function, then the stream
must be seekable. Note that the file pointer position is not changed after this function returns.
</para>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>exif_thumbnail</function></member>
<member><function>getimagesize</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->