使用 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

我想知道是否有人在使用 PHP 的 EXIF 2.3 exif_read_data()提取 GPS 甚至所有 EXIF 数据时遇到过问题(并且可能找到了解决方案)。我的公司最近购买了一台富士胶片Finepix XP150,它可以提供GPS方向数据,这对于我为公司构建的工具至关重要。

下面的代码是我用来提取的代码,我正在传递一次以获取整个EXIF数据的列表,第二次是给我经度和纬度。

$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 />";
    }

使用三星Galaxy Nexus拍摄照片时,我获得了完美的结果,我获得了适当的GPS数据和所有EXIF数据,使用相机时,我得到了exif_read_data(DSCF0006.JPG) [exif_read_data]: corrupt EXIF header: maximum directory nesting level reached

是我做错了什么,还是 PHP 5 的exif_read_data还不支持 EXIF 2.3?我对此进行了研究,PHP.net 指出:

exif_read_data() also validates EXIF data tags according to the EXIF
specification (» http://exif.org/Exif2-2.PDF, page 20).

我也有一台富士相机有同样的问题,但我想我已经找到了解决方案,我在这里提出了一个PHP错误报告:https://bugs.php.net/bug.php?id=66443

如果可以从源代码编译 PHP,请增加 exif.c 文件中MAX_IFD_NESTING_LEVEL的值。我将其从 100 提高到 200,它似乎已经解决了问题。