使用PHP 5.2.9为exif 2.3提取exif数据的问题 [英] Issues extracting exif data for exif 2.3 using PHP Version 5.2.9
问题描述
PHP版本5.2.9
我想知道是否有人遇到问题(并可能找到解决方案),通过提取GPS甚至所有EXIF数据使用PHP的 exif_read_data()
用于EXIF 2.3。我的公司最近购买了一款支持GPS定向数据的Fujifilm Finepix XP150,这对于我为我公司生产的一款工具来说是必不可少的。
$ exif = exif_read_data('./ images / DSCF0006.JPG','GPS');
echo $ exif === false? < strong>没有找到标题数据。< / strong>< br /> \\\
:< strong>图像包含标题< / strong>< br /> \\\
;
$ exif = exif_read_data('./ images / DSCF0006.JPG',0,true);
echo< strong> IMG_20120329_104351.jpg:< / strong>< br /> \\\
;
foreach($ exif as $ key => $ section){
foreach($ section as $ name => $ val){
echo$ key。$ name:$ val< ; \\ n;
$ / code $ / pre
$ dir =./images/;
函数readGPSinfoEXIF($ image_full_name){
$ exif = exif_read_data($ image_full_name,0,true);
if(!$ exif || $ exif ['GPS'] ['GPSLatitude'] ==''){
return false;
} else {
$ lat_ref = $ exif ['GPS'] ['GPSLatitudeRef'];
echoLattitude Reference:,$ lat_ref,< br />;
$ lat = $ exif ['GPS'] ['GPSLatitude'];
list($ num,$ dec)= explode('/',$ lat [0]);
$ lat_s = $ num / $ dec;
list($ num,$ dec)= explode('/',$ lat [1]);
$ lat_m = $ num / $ dec;
list($ num,$ dec)= explode('/',$ lat [2]);
$ lat_v = $ num / $ dec;
$ lon_ref = $ exif ['GPS'] ['GPSLongitudeRef'];
echoLongitude Reference:,$ lon_ref,< br />;
$ lon = $ exif ['GPS'] ['GPSLongitude'];
list($ num,$ dec)= explode('/',$ lon [0]);
$ lon_s = $ num / $ dec;
list($ num,$ dec)= explode('/',$ lon [1]);
$ lon_m = $ num / $ dec;
list($ num,$ dec)= explode('/',$ lon [2]);
$ lon_v = $ num / $ dec;
$ lat_int =($ lat_s + $ lat_m / 60.0 + $ lat_v / 3600.0);
//如果S
$ lat_int =($ lat_ref ==S),检查纬度方向和前缀( - )? ' - '。 $ lat_int:$ lat_int;
$ lon_int =($ lon_s + $ lon_m / 60.0 + $ lon_v / 3600.0);
//检查经度的方向和前缀( - )如果W
$ lon_int =($ lon_ref ==W)? ' - '。 $ lon_int:$ lon_int;
$ gps_int = array($ lat_int,$ lon_int);
返回$ gps_int;
函数dirImages($ dir){
$ d = dir($ dir);
while(false!==($ file = $ d-> read())){
$ extension = substr($ file,strrpos($ file,'。'));
if($ extension ==.JPG|| $ extension ==.jpeg|| $ extension ==.gif| $ extension ==.png){
$ images [$ file] = $ file;
}
$ d-> close();
返回$图片;
}
$ array = dirImages('./ images /');
$ counter = 0;
foreach($ array as $ key => $ image){
echo< br />;
$ counter ++;
回声< strong>。$ counter。< / strong>;
echo:;
$ image_full_name = $ dir。/。$ key;
$ image_name = $ key;
回声< strong>。$ image_name。< / strong>;
回声< br />;
$ results = readGPSinfoEXIF($ image_full_name);
$ latitude = $ results [0];
echo $ latitude;
echo,;
$ longitude = $ results [1];
echo $ longitude;
回声< br />;
}
使用Samsung Galaxy Nexus拍摄照片时可以获得完美效果,使用相机时适当的GPS数据和所有EXIF数据我得到 exif_read_data(DSCF0006.JPG)[exif_read_data]:损坏的EXIF标头:达到最大目录嵌套级别
这是我做错了什么,或者PHP 5的 exif_read_data
不支持EXIF 2.3吗?我已经研究了这一点,PHP.net指出:
exif_read_data()也根据EXIF
验证EXIF数据标签规范(»http://exif.org/Exif2-2.PDF,第20页)。
解决方案我也有一台Fujifilm相机,但我想我已经找到了解决方案,我在这里提出了PHP错误报告:
https://bugs.php.net/bug.php?id=66443
如果您可以从源代码编译PHP,请增加该值MAX_IFD_NESTING_LEVEL在exif.c文件中。我把它从100提升到200,似乎解决了这个问题。
PHP Version 5.2.9
I was wondering if anyone has experienced issues (and possibly found a resolution) with extracting GPS or even just all EXIF data using PHP's exif_read_data()
for EXIF 2.3. My company recently bought a Fujifilm Finepix XP150 which allows for GPS directional data, this is essential for a tool I am building for my company.
The code below is what I am using to extract, I am passing through once for a list of the entire EXIF data and the second time is giving me the longitude and latitude.
$exif = exif_read_data('./images/DSCF0006.JPG', 'GPS');
echo $exif===false ? "<strong>No header data found.</strong><br />\n" : "<strong>Image contains headers</strong><br />\n";
$exif = exif_read_data('./images/DSCF0006.JPG', 0, true);
echo "<strong>IMG_20120329_104351.jpg:</strong><br />\n";
foreach ($exif as $key => $section) {
foreach ($section as $name => $val) {
echo "$key.$name: $val<br />\n";
}
}
$dir = "./images/";
function readGPSinfoEXIF($image_full_name) {
$exif=exif_read_data($image_full_name, 0, true);
if(!$exif || $exif['GPS']['GPSLatitude'] == '') {
return false;
} else {
$lat_ref = $exif['GPS']['GPSLatitudeRef'];
echo "Lattitude Reference: ", $lat_ref, "<br />";
$lat = $exif['GPS']['GPSLatitude'];
list($num, $dec) = explode('/', $lat[0]);
$lat_s = $num / $dec;
list($num, $dec) = explode('/', $lat[1]);
$lat_m = $num / $dec;
list($num, $dec) = explode('/', $lat[2]);
$lat_v = $num / $dec;
$lon_ref = $exif['GPS']['GPSLongitudeRef'];
echo "Longitude Reference: ", $lon_ref, "<br />";
$lon = $exif['GPS']['GPSLongitude'];
list($num, $dec) = explode('/', $lon[0]);
$lon_s = $num / $dec;
list($num, $dec) = explode('/', $lon[1]);
$lon_m = $num / $dec;
list($num, $dec) = explode('/', $lon[2]);
$lon_v = $num / $dec;
$lat_int = ($lat_s + $lat_m / 60.0 + $lat_v / 3600.0);
// check orientation of latitude and prefix with (-) if S
$lat_int = ($lat_ref == "S") ? '-' . $lat_int : $lat_int;
$lon_int = ($lon_s + $lon_m / 60.0 + $lon_v / 3600.0);
// check orientation of longitude and prefix with (-) if W
$lon_int = ($lon_ref == "W") ? '-' . $lon_int : $lon_int;
$gps_int = array($lat_int, $lon_int);
return $gps_int;
}
}
function dirImages($dir) {
$d = dir($dir);
while (false!== ($file = $d->read())) {
$extension = substr($file, strrpos($file, '.'));
if($extension == ".JPG" || $extension == ".jpeg" || $extension == ".gif" | $extension == ".png") {
$images[$file] = $file;
}
$d->close();
return $images;
}
$array = dirImages('./images/');
$counter = 0;
foreach ($array as $key => $image) {
echo "<br />";
$counter++;
echo "<strong>".$counter."</strong>";
echo ": ";
$image_full_name = $dir."/".$key;
$image_name = $key;
echo "<strong>".$image_name."</strong>";
echo "<br />";
$results = readGPSinfoEXIF($image_full_name);
$latitude = $results[0];
echo $latitude;
echo ", ";
$longitude = $results[1];
echo $longitude;
echo "<br />";
}
I get perfect results when capturing photos using my Samsung Galaxy Nexus, I get the appropriate GPS data and all EXIF data, when using the Camera I get exif_read_data(DSCF0006.JPG) [exif_read_data]: corrupt EXIF header: maximum directory nesting level reached
Is it something I am doing wrong or does PHP 5's exif_read_data
not support EXIF 2.3 yet? I have researched this, PHP.net states:
exif_read_data() also validates EXIF data tags according to the EXIF
specification (» http://exif.org/Exif2-2.PDF, page 20).
解决方案 I also have a Fujifilm camera with the same problem, but I think I've found the solution, I've raised a PHP bug report here:
https://bugs.php.net/bug.php?id=66443
If you can compile PHP from source, increase the value of MAX_IFD_NESTING_LEVEL in the exif.c file. I raised it from 100 to 200 and it appears to have fixed the problem.
这篇关于使用PHP 5.2.9为exif 2.3提取exif数据的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!