From - darkain at darkain dot com 's example.
If all the data is from the same image - simply
<?php
$exif_data = exif_read_data ( $_FILES['photo']
$emake =$exif_data['Make'];
$emodel = $exif_data['Model'];
$eexposuretime = $exif_data['ExposureTime'];
$efnumber = $exif_data['FNumber'];
$eiso = $exif_data['ISOSpeedRatings'];
$edate = $exif_data['DateTime'];
?>
will work, I tried using the PEL library, and while pretty cool, I can't for the life understand how to call some things, this is simpler if your system is pretty basic or if you're in a rush. If you have time, try playing with PEL. It's not maintained at the moment though..
http://pel.sourceforge.net/
exif_read_data
(PHP 4 >= 4.2.0, PHP 5)
exif_read_data — JPEG あるいは TIFF から EXIF ヘッダを読み込む
説明
exif_read_data() は、JPEG あるいは TIFF の画像ファイルから EXIF ヘッダを読み込みます。この方法で、デジタルカメラが生成したメタデータを 読み込むことが可能です。
EXIF ヘッダは、デジタルカメラが作成した JPEG/TIFF 画像によく含まれています。しかし残念なことに、 そのタグ付けの方法はメーカーによって異なります。 したがって、特定の Exif ヘッダが常に存在すると仮定することはできません。
Height および Width は、getimagesize() と同じ方法で計算されます。 よって、これらの値は決してヘッダの一部として返してはいけません。 また、html は高さ/幅を表すテキスト文字列で、 通常の HTML の中で用いられます。
Exif ヘッダに著作権表示が含まれている場合、それ自身には 2 つの値を 含めることが可能です。Exif 2.10 のこの矛盾した規格に対応するため、 COMPUTED セクションは Copyright.Photographer および Copyright.Editor の両方を返します。 また IFD0 セクションには 2 つのエントリを NULL 文字で区切った バイト配列を含めます。データ型が間違っている場合は最初のエントリのみを かえします(Exif の通常の挙動)。COMPUTED には、元の著作権文字列あるいは カンマで区切られた写真と編集者の著作権表示のどちらかを Copyright エントリに含めることが可能です。
UserComment タグにも Copyright タグと同様の問題があります。ここにも 2 つの値を格納することが可能です。それは使用しているエンコーディングと 値自身の 2 つです。そうなると、IFD セクションにはエンコーディングのみを 含めるか、あるいはバイト配列を格納することになります。COMPUTED セクションは UserCommentEncoding および UserComment を両方格納することができます。UserComment はどちらの 場合でも有効なので、IFD0 セクションではこちらを優先すべきです。
exif_read_data() は、EXIF 仕様(» http://exif.org/Exif2-2.PDF, 20 ページ)に基づいて EXIF データタグの検証も行います。
注意: Windows ME/XP は、カメラと接続した際に Exif ヘッダを書き換えることが可能です。 詳細な情報は » http://www.canon.co.jp/Imaging/NOTICE/011214-e.html を参照ください。
パラメータ
- filename
-
読み込む画像ファイルの名前。 URL 形式は使用できません。
- sections
-
結果の配列を作成するために存在する必要のあるセクションのカンマ区切り リスト。要求されたセクションがひとつも見つからなかった場合の返り値は FALSE となります。
FILE FileName, FileSize, FileDateTime, SectionsFound COMPUTED html, Width, Height, IsColor, および他の取得可能なもの。Height および Width は getimagesize() と同じ方法で取得した もので、その値はヘッダの一部ではありません。また、html は 通常の HTML 内で使用される height/width の 文字列です。 ANY_TAG タグを有するすべての情報。例えば IFD0, EXIF, ... IFD0 IFD0 のすべてのタグつきデータ。通常の画像ファイルでは、 ここに画像のサイズが含まれます。 THUMBNAIL 2 番目の IFD がある場合、ファイルにサムネイルが含まれている 可能性があります。埋め込まれたサムネイルに関するすべての タグつき情報はこのセクションに格納されます。 COMMENT JPEG 画像のコメントヘッダ。 EXIF EXIF セクションは IFD0 のサブセクションです。ここには 画像に関する詳細な情報が含まれています。これらのエントリの ほとんどはデジタルカメラに関連するものです。 - arrays
-
各セクションを配列とするかどうかを指定します。 COMPUTED、 THUMBNAIL および COMMENT のセクションは常に配列となります。これは、これらのセクションに 含まれる値の名前が他のセクションと衝突する可能性があるからです。
- thumbnail
-
TRUE を指定すると、サムネイル本体を読み込みます。それ以外の場合は タグつきデータのみを読み込みます。
返り値
ヘッダ名がキー・ヘッダの内容が値となる連想配列を返します。 返されるデータがない場合は exif_read_data() は FALSE を返します。
変更履歴
| バージョン | 説明 |
|---|---|
| 4.3.0 | 埋め込まれた IFD データを、配列を含めて すべて読み込めます(そして返せます)。また、埋め込まれた サムネイルの大きさもサブ配列 THUMBNAIL に 格納され、TIFF フォーマットのサムネイルを 返すことが可能です。さらに、(メモリの制限に達しない限り) 返り値の長さの最大長には制限はありません。 |
| 4.3.0 | PHP の mbstring サポートが 有効になっている場合、ユーザコメントのエンコーディングは自動的に 変換されます。また、ユーザコメントが Unicode あるいは JIS エンコーディングを使用している場合は php.ini の exif 設定に応じて エンコーディングが自動的に変換されます。 |
| 4.3.0 | 画像に何らかの IFD0 データが含まれている場合、 COMPUTED にはエントリ ByteOrderMotorola が含まれます。このエントリは、バイトオーダーが リトルエンディアン(intel)の場合に 0 、ビッグエンディアン (motorola)の場合に 1 となります。また、COMPUTED および UserComment は、仮にデータ型が間違っていても最初の copyright エントリだけを格納するということはありません。 |
例
例1 exif_read_data() の例
<?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";
}
}
?>
最初のコールは失敗します。画像がヘッダ情報を有していないためです。
上の例の出力は、たとえば 以下のようになります。
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
exif_read_data
21-Nov-2008 02:01
27-Sep-2008 08:57
Get some EXIFs fields (easy way):
<?php
$exif_make = exif_read_data ( $_FILES['photo']['tmp_name'] ,'IFD0' ,0 );
$emake = $exif_make['Make'];
$exif_model = exif_read_data ( $_FILES['photo']['tmp_name'] ,'IFD0' ,0 );
$emodel = $exif_model['Model'];
$exif_exposuretime = exif_read_data ( $_FILES['photo']['tmp_name'] ,'EXIF' ,0 );
$eexposuretime = $exif_exposuretime['ExposureTime'];
$exif_fnumber = exif_read_data ( $_FILES['photo']['tmp_name'] ,'EXIF' ,0 );
$efnumber = $exif_fnumber['FNumber'];
$exif_iso = exif_read_data ( $_FILES['photo']['tmp_name'] ,'EXIF' ,0 );
$eiso = $exif_iso['ISOSpeedRatings'];
$exif_date = exif_read_data ( $_FILES['photo']['tmp_name'] ,'IFD0' ,0 );
$edate = $exif_date['DateTime'];
?>
29-Jul-2008 03:33
I wanted some quick and easy functions for computing the shutter speed and f-stop. I couldn't find any anywhere, so I made some. It took some research :
<?php
function exif_get_float($value) {
$pos = strpos($value, '/');
if ($pos === false) return (float) $value;
$a = (float) substr($value, 0, $pos);
$b = (float) substr($value, $pos+1);
return ($b == 0) ? ($a) : ($a / $b);
}
function exif_get_shutter(&$exif) {
if (!isset($exif['ShutterSpeedValue'])) return false;
$apex = exif_get_float($exif['ShutterSpeedValue']);
$shutter = pow(2, -$apex);
if ($shutter == 0) return false;
if ($shutter >= 1) return round($shutter) . 's';
return '1/' . round(1 / $shutter) . 's';
}
function exif_get_fstop(&$exif) {
if (!isset($exif['ApertureValue'])) return false;
$apex = exif_get_float($exif['ApertureValue']);
$fstop = pow(2, $apex/2);
if ($fstop == 0) return false;
return 'f/' . round($fstop,1);
}
?>
05-Sep-2007 10:20
Using the exif methods to read WINXP data returns unexpected results unless both exif and mbstring are compiled statically. Please reference the following bug reports:
Bug #31980
Bug #23105
Specifically, the last comment on #23105:
"[8 Apr 2003 4:26pm UTC] edink@php.net
This cannot be fixed due to the fact that mbstring has been removed from PHP core (it has been 'unbundled') and the rest of core files and other extensions cannot use mbstring functionality when it is compiled as a shared library (dll).
"
If exif is compiled statically (--enable-exif) and mbstring compiled as a DSO module (--enable-mbstring=shared) then exif_read_data may only return a single character rather than the entire string.
Compiling both exif and mbstring statically (--enable-exif --enable-mbstring) resolves the issue.
08-Aug-2007 05:57
some cameras (most higher models) have position senzor (gyroskope?) and taking-position is wrote in EXIF, here is simple script for automatic rotating images
<?php
$exif = exif_read_data($filename);
$ort = $exif['IFD0']['Orientation'];
switch($ort)
{
case 1: // nothing
break;
case 2: // horizontal flip
$image->flipImage($public,1);
break;
case 3: // 180 rotate left
$image->rotateImage($public,180);
break;
case 4: // vertical flip
$image->flipImage($public,2);
break;
case 5: // vertical flip + 90 rotate right
$image->flipImage($public, 2);
$image->rotateImage($public, -90);
break;
case 6: // 90 rotate right
$image->rotateImage($public, -90);
break;
case 7: // horizontal flip + 90 rotate right
$image->flipImage($public,1);
$image->rotateImage($public, -90);
break;
case 8: // 90 rotate left
$image->rotateImage($public, 90);
break;
}
?>
$image->rotateImage() is inspired by example of http://php.net/manual/en/function.imagerotate.php
$image->flipImage() is inspired by http://php.net/manual/en/function.imagecopy.php#42803 (thank you)
When reading EXIF information from the 'WINXP' group, you may need to change used encoding from the default "ISO-8859-15" to "UTF-8". This can be done in php.ini or in your code:
<?php
ini_set('exif.encode_unicode', 'UTF-8');
$exif = exif_read_data('TEST.JPG', 0, true);
echo $exif['WINXP']['Title'];
?>
Useful documentation about EXIF:
http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html
See also comments next to XPTitle and XPAuthor.
I've just released the "PHP JPEG Metadata Toolkit" which allows reading, writing and displaying of EXIF information, and does not need the --enable-exif option in PHP4.
It has been tested on 466 different models of digital cameras!
It can decode the following EXIF makernotes:
Agfa, Canon, Casio, Contax, Epson, Fujifilm, Konica, Minolta, Kyocera, Nikon, Olympus, Panasonic, Pentax (Asahi), Ricoh and Sony
Additionaly it can decode IPTC, XMP, Photoshop IRB and many other types of JPEG metadata
Try it out, and download it at:
http://www.ozhiker.com/electronics/pjmt/index.html
18-May-2004 08:24
I've written a library in pure PHP5 for editing EXIF tags. It deals with both reading and writing EXIF tags, and can be downloaded from http://pel.sourceforge.net/
24-Feb-2004 01:44
Exif is very unstable under php4.1.2
If you have some problem, (the function didnt return anything, like a blocking call) try this:
$file = './image.jpg';
getimagesize ( $file , $info);
$exif = array();
if (isset($info)) {
foreach($info as $key => $val) {
if ($key != 'APP1') { $exif = read_exif_data($file); break; }
}
}
-- Sharp
20-Nov-2003 10:50
For reading EXIF from XMP data embedded by Adobe Photoshop CS, see http://www.photography-on-the.net/ee/beta/cs_xmp_to_exif.php
