检查是否exif纬度&经度存在于图像中

时间:2015-09-20 11:46:49

标签: php gps latitude-longitude

所以我正在使用read_exif_data函数,并遇到了一个小问题。 如果图像没有经度,我必须停止文件上传。纬度。

问题是我无法找到检查gps数组是否在exif数据中的方法。

我正在从$ _ FILES ['spotImg'] ['tmp_name']中读取数据而且我确实得到了我所知道的exif。

问题仅在图像中没有gps数据时。

if($_FILES['spotImg']['error'] == 0){

            $file = "image_".uniqid(). $_FILES['spotImg']['name'];
            $img = WideImage::loadFromFile($_FILES['spotImg']['tmp_name']);

            //check if exif data is avalible
            $temp = $_FILES['spotImg']['tmp_name'];
            $exif = read_exif_data($temp, 0, true);

            echo "<pre">;
            print_r($exif);
            echo "</pre>;

}

这就是我的想法,但它不能正常工作

if(isset($exif['GPSLatitude'])){
     //run code if long/latitude was found
   }else{
    //give a error message if long/latitude was NOT found
}

这是我想检查的数组是否存在

[GPS] => Array
    (
        [GPSLatitudeRef] => N
        [GPSLatitude] => Array
            (
                [0] => 55/1
                [1] => 41/1
                [2] => 2846/100
            )

        [GPSLongitudeRef] => E
        [GPSLongitude] => Array
            (
                [0] => 12/1
                [1] => 33/1
                [2] => 1568/100
            )

        [GPSAltitudeRef] => 
        [GPSAltitude] => 68780/4027
        [GPSTimeStamp] => Array
            (
                [0] => 12/1
                [1] => 48/1
                [2] => 4621/100
            )

        [GPSSpeedRef] => K
        [GPSSpeed] => 0/1
        [GPSDateStamp] => 2015:09:16
    )

2 个答案:

答案 0 :(得分:0)

我在阅读图像的[&#39; orientation&#39;]属性方面遇到了类似的问题;有些人没有。

我找到的解决方案是使用!empty()进行检查,如下所示:

if(!empty($exif['GPSLatitude'])){
  //run code if long/latitude was found
}else{
  //give an error message if long/latitude was NOT found
}

此检查应该可以正常运行而不会出现任何错误。

答案 1 :(得分:0)

  

read_exif_data()别名–已弃用。请改用exif_read_data()函数

Read the docs

相关问题