Skip to content
Snippets Groups Projects

Generate CVS output for use with uMap

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Dmitri Popov
    Edited
    cvs.php 1.30 KiB
    <?php
    
    $url = "http://dmpop.dhcp.io/mejiro";
    $photos = "photos";
    $thumbnails = "tims";
    
    function gps($coordinate, $hemisphere) {
        for ($i = 0; $i < 3; $i++) {
            $part = explode('/', $coordinate[$i]);
            if (count($part) == 1) {
            $coordinate[$i] = $part[0];
            } else if (count($part) == 2) {
            $coordinate[$i] = floatval($part[0])/floatval($part[1]);
            } else {
            $coordinate[$i] = 0;
            }
        }
        list($degrees, $minutes, $seconds) = $coordinate;
        $sign = ($hemisphere == 'W' || $hemisphere == 'S') ? -1 : 1;
        return $sign * ($degrees + $minutes/60 + $seconds/3600);
    }
    
    $files = glob($photos.DIRECTORY_SEPARATOR.'*.{jpg,jpeg,JPG,JPEG}', GLOB_BRACE);
    $fileCount = count($files);
    
    echo "lat,lon,thumbnail,photo\n";
    for ($i=($fileCount-1); $i>=0; $i--) {
        $file = $files[$i];
    	$photo_url = $url.DIRECTORY_SEPARATOR.$photos.DIRECTORY_SEPARATOR.basename($file);
    	$thumbnail_url = $url.DIRECTORY_SEPARATOR.$photos.DIRECTORY_SEPARATOR.$thumbnails.DIRECTORY_SEPARATOR.basename($file);
    	$filepath = pathinfo($file);
    	$exif = exif_read_data($file);
    	$lat = gps($exif["GPSLatitude"], $exif['GPSLatitudeRef']);
    	$lon = gps($exif["GPSLongitude"], $exif['GPSLongitudeRef']);
    	$exif = exif_read_data($file, 0, true);
    	echo $lat.",".$lon.",".$thumbnail_url.",".$photo_url."\n";
    }
    
    ?>
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment