PHP extract GPS EXIF data

前端 未结 13 1443
执笔经年
执笔经年 2020-11-29 16:26

I would like to extract the GPS EXIF tag from pictures using php. I\'m using the exif_read_data() that returns a array of all tags + data :

GPS.         


        
13条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 16:55

    In case you need a function to read Coordinates from Imagick Exif here we go, I hope it saves you time. Tested under PHP 7.

    function create_gps_imagick($coordinate, $hemi) {
    
      $exifCoord = explode(', ', $coordinate);
    
      $degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;
      $minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
      $seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;
    
      $flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1;
    
      return $flip * ($degrees + $minutes / 60 + $seconds / 3600);
    
    }
    
    function gps2Num($coordPart) {
    
        $parts = explode('/', $coordPart);
    
        if (count($parts) <= 0)
            return 0;
    
        if (count($parts) == 1)
            return $parts[0];
    
        return floatval($parts[0]) / floatval($parts[1]);
    }
    

提交回复
热议问题