EXIF and PHP, how to find where have you been

April 16, 2012 at 15:51

This post got my attention (link). I won't talk about conspiracy theories and stuff. I knew that images store some kind of personal information but I didn't know how to extract it and may be I never asked myself how to do it. So after I saw this post by Gatakka, I decided to dig into the deep and do something creative:

geoimg.ava7.eu

It's very simple actually and it took me several hours to build it. All you need to know is how to work with exif_read_data function. Here's the class that makes the big deal. I hope you'd like it:

class Exif {

    private $_lat = 0, $_long = 0;
    private $_basicInfo = array();

    public function checkExif($img) {
        $arr = exif_read_data($img, 'GPS');
        $this->_basicInfo = array(
            'Model' => $arr['Model'], 'Produced by' => $arr['Make'], 'Date taken' => $arr['DateTime'],
            'Sixes' => $arr['COMPUTED']['html']
        );
        if ($arr) {
            $this->_lat = explode('/', $arr['GPSLatitude'][1]);
            $this->_lat = $this->_lat[0] / $this->_lat[1];
            $this->_long = explode('/', $arr['GPSLongitude'][1]);
            $this->_long = $this->_long[0] / $this->_long[1];

            //get degrees
            $dlat = explode('/', $arr['GPSLatitude'][0]);
            $dlong = explode('/', $arr['GPSLongitude'][0]);
            //get seconds
            $slat = explode('/', $arr['GPSLatitude'][2]);
            $slong = explode('/', $arr['GPSLongitude'][2]);

            $this->_lat = $this->_calc($dlat[0], $this->_lat, $slat[0]);
            $this->_long = $this->_calc($dlong[0], $this->_long, $slong[0]);

            if (strtoupper($arr['GPSLatitudeRef']) == 'S') {
                $this->_lat = '-' . $this->_lat;
            } if (strtoupper($arr['GPSLongitudeRef']) == 'W') {
                $this->_long = '-' . $this->_long;
            }
            return true;
        } else {
            return false;
        }
    }

    private function _calc($degree, $min, $sec) {
        //Decimal degrees = whole number of degrees, plus minutes divided by 60, plus seconds divided by 3600
        return number_format($degree + ($min / 60) + ($sec / 3600), 5);
    }

}

It doesn't work with every single picture. First, file format should be either tif or jpg and second - the image must contain GPS information. Have fun using it! :)

there are no comments yet :(

meow + meow =

friends

find me

  • google plus
  • linked in
  • youtube