-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
135 lines (119 loc) · 4.61 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
$photo_dir = "photos";
$ext = "jpg,JPG,jpeg,JPEG";
// Check whether the php-exif library is installed
if (!extension_loaded('exif')) {
exit("<center><code style='color: red;'>php-exif is not installed</code></center>");
}
// Create $photo_dir if it doesn't exist
if (!file_exists($photo_dir)) {
mkdir($photo_dir, 0755, true);
}
$photos = glob($photo_dir . DIRECTORY_SEPARATOR . '*.{' . $ext . '}', GLOB_BRACE);
// Count all photos in $photo_dir
$total_count = count($photos);
// Check if $photo_dir is empty
if ($total_count === 0) {
exit("<center><code style='color: red;'>No photos found</code></center>");
} else {
// Find the most recent photo to center the map on
// $total_count-1 because arrays start with 0
$last_photo = $photos[$total_count - 1];
};
/* EXTRACT LATITUDE AND LONGITUDE ---START---
* https://stackoverflow.com/a/16437888
*/
function gps($coordinate, $hemisphere)
{
if (is_string($coordinate)) {
$coordinate = array_map("trim", explode(",", $coordinate));
}
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);
}
/* EXTRACT LATITUDE AND LONGITUDE ---END--- */
// Find and remove photos that are not geotagged
foreach ($photos as $file) {
// Get latitude and longitude values
$exif = @exif_read_data($file, 0, true);
$lat = gps($exif["GPS"]["GPSLatitude"], $exif["GPS"]["GPSLatitudeRef"]);
$lon = gps($exif["GPS"]["GPSLongitude"], $exif["GPS"]["GPSLongitudeRef"]);
if (!isset($lat) && !isset($lon)) {
unlink($file);
}
}
?>
<!DOCTYPE html>
<!--
Author: Dmitri Popov
License: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
Source code: https://github.com/dmpop/pinpinpin
-->
<html>
<head>
<title>PinPinPin</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="favicon.png" />
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="leaflet/leaflet.css" />
<script src="leaflet/leaflet.js"></script>
<link rel="stylesheet" href="leaflet/MarkerCluster.css" />
<link rel="stylesheet" href="leaflet/MarkerCluster.Default.css" />
<script src="leaflet/leaflet.markercluster.js"></script>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
var tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, This is <a href="https://github.com/dmpop/pinpinpin">PinPinPin</a>. Photos: <?php echo $total_count; ?>'
});
var map = L.map('map', {
zoom: 9,
layers: [tiles]
});
var Pin = L.icon({
iconUrl: 'pins/pin.png',
shadowUrl: 'pins/pin-shadow.png',
});
var markers = L.markerClusterGroup();
<?php
foreach ($photos as $file) {
// Get latitude and longitude values
$exif = @exif_read_data($file, 0, true);
$lat = gps($exif["GPS"]["GPSLatitude"], $exif["GPS"]["GPSLatitudeRef"]);
$lon = gps($exif["GPS"]["GPSLongitude"], $exif["GPS"]["GPSLongitudeRef"]);
if (empty($exif['COMMENT']['0'])) {
$caption = "";
} else {
$caption = $exif['COMMENT']['0'];
$caption = str_replace(array("\r", "\n"), '', $caption);
}
echo 'var marker = L.marker(new L.LatLng(' . $lat . ', ' . $lon . '), {icon: Pin});';
echo "marker.bindPopup('<a href=\"" . $file . "\" target=\"_blank\"><img src=\"tim.php?image=" . $file . "\" width=300px /></a>" . $caption . "');";
echo 'markers.addLayer(marker);';
}
?>
map.addLayer(markers);
<?php
// Get latitude and longitude values og the last photo
$exif = @exif_read_data($last_photo, 0, true);
$lat = gps($exif["GPS"]["GPSLatitude"], $exif["GPS"]["GPSLatitudeRef"]);
$lon = gps($exif["GPS"]["GPSLongitude"], $exif["GPS"]["GPSLongitudeRef"]);
?>
map.panTo(new L.LatLng(<?php echo $lat; ?>, <?php echo $lon; ?>));
</script>
</body>
</html>