php-doc-en/reference/exif/functions/exif-read-data.xml
Dave Barr 9ce5713d6c - Fix up some example layouts.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@165326 c90b9560-bf6c-de11-be94-00142212c4b1
2004-08-04 21:03:59 +00:00

252 lines
No EOL
9 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
<!-- splitted from ./en/functions/image.xml, last change in rev 1.78 -->
<refentry id="function.exif-read-data">
<refnamediv>
<refname>exif_read_data</refname>
<refpurpose>Reads the <acronym>EXIF</acronym> headers from <acronym>JPEG</acronym>
or <acronym>TIFF</acronym></refpurpose>
</refnamediv>
<refsect1>
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>exif_read_data</methodname>
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>sections</parameter></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>arrays</parameter></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>thumbnail</parameter></methodparam>
</methodsynopsis>
<para>
The <function>exif_read_data</function> function reads the
<acronym>EXIF</acronym> headers from a <acronym>JPEG</acronym> or
<acronym>TIFF</acronym> image file. This way you can read meta data
generated by digital cameras.
</para>
<para>
<parameter>filename</parameter> is the name of the file to read. This
cannot be a URL.
</para>
<para>
<parameter>sections</parameter> is a comma separated list of sections that
need to be present in file to produce a result array. If none of the
requested sections could be found the return value is &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 and some more if available.
</entry>
</row>
<row>
<entry>ANY_TAG</entry>
<entry>Any information that has a Tag e.g. IFD0, EXIF, ...</entry>
</row>
<row>
<entry>IFD0</entry>
<entry>All tagged data of IFD0. In normal imagefiles this contains
image size and so forth.</entry>
</row>
<row>
<entry>THUMBNAIL</entry>
<entry>A file is supposed to contain a thumbnail if it has a second IFD.
All tagged information about the embedded thumbnail is stored in this
section.</entry>
</row>
<row>
<entry>COMMENT</entry>
<entry>Comment headers of JPEG images.</entry>
</row>
<row>
<entry>EXIF</entry>
<entry>The EXIF section is a sub section of IFD0. It contains
more detailed information about an image. Most of these entries
are digital camera related.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
<para>
<parameter>arrays</parameter> specifies whether or not each section
becomes an array. The sections <emphasis>COMPUTED</emphasis>,
<emphasis>THUMBNAIL</emphasis> and <emphasis>COMMENT</emphasis> always
become arrays as they may contain values whose names are conflict
with other sections.
</para>
<para>
<parameter>thumbnail</parameter> whether or not to read the thumbnail
itself and not only its tagged data.
</para>
<note>
<para>
Exif headers tend to be present in JPEG/TIFF images generated by digital
cameras, but unfortunately each digital camera maker has a different
idea of how to actually tag their images, so you can't always rely on
a specific Exif header being present.
</para>
<para>
Windows ME/XP both can wipe the Exif headers when connecting to a camera.
More information available at <ulink
url="&url.winexif;">&url.winexif;</ulink>.
</para>
</note>
<note>
<para>
If the image contains any IFD0 data then COMPUTED contains the entry
ByteOrderMotorola which is 0 for little-endian (intel) and 1 for
big-endian (motorola) byte order. This was added in PHP 4.3.0.
</para>
<para>
When an Exif header contains a Copyright note this itself can contain two
values. As the solution is inconsistent in the Exif 2.10 standard the COMPUTED
section will return both entries <emphasis>Copyright.Photographer</emphasis>
and <emphasis>Copyright.Editor</emphasis> while the IFD0 sections contains
the byte array with the NULL character that splits both entries. Or just the
first entry if the datatype was wrong (normal behaviour of Exif). The
COMPUTED will contain also an entry <emphasis>Copyright</emphasis> Which
is either the original copyright string or it is a comma separated list of
photo and editor copyright.
</para>
</note>
<note>
<para>
The tag UserComment has the same problem as the Copyright tag. It can store
two values first the encoding used and second the value itself. If so the
IFD section only contains the encoding or a byte array. The COMPUTED section
will store both in the entries <emphasis>UserCommentEncoding</emphasis> and
<emphasis>UserComment</emphasis>. The entry <emphasis>UserComment</emphasis>
is available in both cases so it should be used in preference to the value
in IFD0 section.
</para>
<para>
If the user comment uses Unicode or JIS encoding and the module mbstring is
available this encoding will automatically changed according to the exif
ini settings in the &php.ini;. This was added in PHP 4.3.0.
</para>
</note>
<note>
<para>
Height and Width are computed the same way <function>getimagesize</function>
does so their values must not be part of any header returned. Also html is
a height/width text string to be used inside normal <acronym>HTML</acronym>.
</para>
</note>
<note>
<para>
Starting from PHP 4.3.0, the function can read all embedded
<acronym>IFD</acronym> data including arrays (returned as such). Also
the size of an embedded thumbnail is returned in
<emphasis>THUMBNAIL</emphasis> subarray and the function
<function>exif_read_data</function> can return thumbnails in
<acronym>TIFF</acronym> format. Also as of PHP 4.3.0 there is no longer
a maximum length for returned values (not until memory limit is reached).
</para>
</note>
<simpara>
Since PHP 4.3,0 user comment can automatically change encoding if PHP was
compiled using <option role="configure">--enable-mbstring</option>.
</simpara>
</refsect1>
<refsect1>
&reftitle.returnvalues;
<para>
It returns an associative <type>array</type> where the array indexes are
the header names and the array values are the values associated with
those headers. If no data can be returned,
<function>exif_read_data</function> will return &false;.
</para>
</refsect1>
<refsect1>
&reftitle.examples;
<para>
<example>
<title><function>exif_read_data</function> example</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 />";
$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>
The first call fails because the image has no header information.
</para>
<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>
</refsect1>
<refsect1>
&reftitle.seealso;
<para>
<function>exif_thumbnail</function>&listendand;
<function>getimagesize</function>.
</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:"../../../../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
-->