Reading Geotag data from image in php

前端 未结 6 1046
醉酒成梦
醉酒成梦 2020-12-28 09:25

Does anyone know if there is a way to read geotag data from photos in PHP?

Thanks

6条回答
  •  Happy的楠姐
    2020-12-28 09:59

    Like everyone else has said, exif_read_data(); will do it. To go ahead and get all of the data, use these args:

    exif_read_data($img, 0, true); // where $img is the path to your image
    

    This function can only read headers from tiffs and jpegs and I'm pretty sure only jpegs may contain geotags. I've written a simple php script for use in the command line and posted it as a gist on github.

    Run the script like this: php exif.php

    It will echo out an array. Look for the coordinates here:

    [GPS] => Array
        [GPSLatitudeRef] => N
        [GPSLatitude] => Array
            [0] => 30/1
            [1] => 1589/100
            [2] => 0/1
        [GPSLongitudeRef] => W
        [GPSLongitude] => Array
            [0] => 87/1
            [1] => 3609/100
            [2] => 0/1
        [GPSAltitudeRef] => 
        [GPSAltitude] => 18289/454
        [GPSTimeStamp] => Array
        [0] => 20/1
        [1] => 22/1
        [2] => 2065/1
        [GPSImgDirectionRef] => T
        [GPSImgDirection] => 34765/689
    

    The Latitude and Longitude arrays contain three values: 0 is for degrees, 1 is for minutes and 2 is for seconds. If you see something like "1589/100" this is equal to 15.89. So for the GPSLongitude array, 3609/100 is equal to 36.09.

    Convert the coordinates from degrees-minutes-second form to decimal form here http://www.satsig.net/degrees-minutes-seconds-calculator.htm

    If the latitude is South, dont forget to make it negative. If the longitude is west, make that negative. The coodinates from the above data are: 30.26483, -87.6015

提交回复
热议问题