|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class ImageMetaDataExtension extends MapExtension |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
public static $db = array( |
|
6
|
|
|
'ExifRead' => 'Boolean', |
|
7
|
|
|
'Aperture' => 'Varchar', |
|
8
|
|
|
'ShutterSpeed' => 'Varchar', |
|
9
|
|
|
'TakenAt' => 'Datetime', |
|
10
|
|
|
'ISO' => 'Int', |
|
11
|
|
|
'Orientation' => 'Int', |
|
12
|
|
|
); |
|
13
|
|
|
|
|
14
|
|
|
public function processExifData() |
|
15
|
|
|
{ |
|
16
|
|
|
$filename = BASE_PATH.'/'.$this->owner->Image()->Filename; |
|
17
|
|
|
|
|
18
|
|
|
// when the image is first saved, the file will still be a temp file |
|
19
|
|
|
if (file_exists($filename)) { |
|
20
|
|
|
try { |
|
21
|
|
|
$exif = exif_read_data($filename, 0, true); |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
$aperture = $exif['COMPUTED']['ApertureFNumber']; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
$aperture = str_replace('f/', '', $aperture); |
|
|
|
|
|
|
26
|
|
|
error_log('APERTURE:'.$aperture); |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
$this->owner->Aperture = $aperture; |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
$shutterspeed = ''; |
|
|
|
|
|
|
31
|
|
|
if (isset($exif['ExposureTime'])) { |
|
|
|
|
|
|
32
|
|
|
$shutterspeed = $exif['ExposureTime']; |
|
|
|
|
|
|
33
|
|
|
} else { |
|
34
|
|
|
$shutterspeed = $exif['EXIF']['ExposureTime']; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
error_log('EXPOSURE:'.$shutterspeed); |
|
38
|
|
|
$this->owner->ShutterSpeed = $shutterspeed; |
|
39
|
|
|
if (isset($exif['DateTimeOriginal'])) { |
|
40
|
|
|
$this->owner->TakenAt = $exif['DateTimeOriginal']; |
|
41
|
|
|
} else { |
|
42
|
|
|
$this->owner->TakenAt = $exif['EXIF']['DateTimeOriginal']; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$iso = ''; |
|
46
|
|
|
if (isset($exif['ISOSpeedRatings'])) { |
|
47
|
|
|
$iso = $exif['ISOSpeedRatings']; |
|
48
|
|
|
} else { |
|
49
|
|
|
$iso = $exif['EXIF']['ISOSpeedRatings']; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$this->owner->ISO = $iso; |
|
53
|
|
|
error_log('ISO:'.$iso); |
|
54
|
|
|
|
|
55
|
|
|
// coors |
|
56
|
|
|
if (isset($exif['GPS'])) { |
|
57
|
|
|
$gps = $exif['GPS']; |
|
58
|
|
|
$latarray = $gps['GPSLatitude']; |
|
59
|
|
|
$degrees = $latarray[0]; |
|
60
|
|
|
$parts = explode('/', $degrees); |
|
61
|
|
|
$degrees = $parts[0] / $parts[1]; |
|
62
|
|
|
$minutes = $latarray[1]; |
|
63
|
|
|
$parts = explode('/', $minutes); |
|
64
|
|
|
$minutes = $parts[0] / $parts[1]; |
|
65
|
|
|
$seconds = $latarray[2]; |
|
66
|
|
|
$parts = explode('/', $seconds); |
|
67
|
|
|
$seconds = $parts[0] / $parts[1]; |
|
68
|
|
|
|
|
69
|
|
|
error_log('LATITUDE: DMS='.$degrees.','.$minutes.','.$seconds); |
|
70
|
|
|
$latitude = $degrees + $minutes / 60 + $seconds / 3600; |
|
71
|
|
|
error_log('LAT:'.$latitude); |
|
72
|
|
|
|
|
73
|
|
|
error_log('LATITUDE:'.$latitude); |
|
74
|
|
|
|
|
75
|
|
|
$lonarray = $gps['GPSLongitude']; |
|
76
|
|
|
$degrees = $lonarray[0]; |
|
77
|
|
|
$parts = explode('/', $degrees); |
|
78
|
|
|
$degrees = $parts[0] / $parts[1]; |
|
79
|
|
|
$minutes = $lonarray[1]; |
|
80
|
|
|
$parts = explode('/', $minutes); |
|
81
|
|
|
$minutes = $parts[0] / $parts[1]; |
|
82
|
|
|
$seconds = $lonarray[2]; |
|
83
|
|
|
$parts = explode('/', $seconds); |
|
84
|
|
|
$seconds = $parts[0] / $parts[1]; |
|
85
|
|
|
|
|
86
|
|
|
$longitude = $degrees + $minutes / 60 + $seconds / 3600; |
|
87
|
|
|
$this->owner->Lat = $latitude; |
|
88
|
|
|
$this->owner->Lon = $longitude; |
|
89
|
|
|
} // else no gps data |
|
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
$image = $this->owner->Image(); |
|
92
|
|
|
if ($image->Height > $image->Width) { |
|
|
|
|
|
|
93
|
|
|
$this->owner->Orientation = 90; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$this->owner->ExifRead = true; |
|
97
|
|
|
$this->owner->write(); |
|
98
|
|
|
} catch (Exception $e) { |
|
99
|
|
|
error_log($e); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function onAfterWriteNOT() |
|
105
|
|
|
{ |
|
106
|
|
|
parent::onAfterWrite(); |
|
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
if (!($this->owner->ExifRead)) { |
|
109
|
|
|
$this->processExifData(); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function requireDefaultRecordsNOT() |
|
114
|
|
|
{ |
|
115
|
|
|
parent::requireDefaultRecords(); |
|
|
|
|
|
|
116
|
|
|
$imagesToProcess = GalleryImage::get()->filter('ExifRead', false); |
|
117
|
|
|
foreach ($imagesToProcess->getIterator() as $image) { |
|
118
|
|
|
$image->processExifData(); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
} |
|
123
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.