-
Notifications
You must be signed in to change notification settings - Fork 37
Geolocation #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Geolocation #30
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,7 +204,7 @@ public function getExifFromFile($file) | |
*/ | ||
public function getIptcData($file) | ||
{ | ||
$size = getimagesize($file, $info); | ||
getimagesize($file, $info); | ||
$arrData = array(); | ||
if (isset($info['APP13'])) { | ||
$iptc = iptcparse($info['APP13']); | ||
|
@@ -262,6 +262,18 @@ public function mapData(array $source) | |
$exposureTime = '1/' . round($denominator); | ||
} | ||
|
||
$gpsLocation = false; | ||
if (isset($source['GPSLatitudeRef']) && isset($source['GPSLongitudeRef'])) { | ||
$latitude = $this->extractGPSCoordinate($source['GPSLatitude']); | ||
$longitude = $this->extractGPSCoordinate($source['GPSLongitude']); | ||
|
||
$gpsLocation = sprintf( | ||
'%s,%s', | ||
(strtoupper($source['GPSLatitudeRef'][0]) === 'S' ? -1 : 1) * $latitude, | ||
(strtoupper($source['GPSLongitudeRef'][0]) === 'W' ? -1 : 1) * $longitude | ||
); | ||
} | ||
|
||
return array( | ||
Exif::APERTURE => (!isset($source[self::SECTION_COMPUTED]['ApertureFNumber'])) ? | ||
false : $source[self::SECTION_COMPUTED]['ApertureFNumber'], | ||
|
@@ -301,6 +313,7 @@ public function mapData(array $source) | |
Exif::VERTICAL_RESOLUTION => $vertResolution, | ||
Exif::WIDTH => (!isset($source[self::SECTION_COMPUTED]['Width'])) ? | ||
false : $source[self::SECTION_COMPUTED]['Width'], | ||
Exif::GPS => $gpsLocation, | ||
); | ||
|
||
$arrMapping = array( | ||
|
@@ -345,4 +358,30 @@ public function mapData(array $source) | |
|
||
return $mappedData; | ||
} | ||
|
||
/** | ||
* Extract GPS coordinates from components array | ||
* | ||
* @param array $components | ||
* @return float | ||
*/ | ||
protected function extractGPSCoordinate(array $components) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you unit test this method? Coverage is brought down now, which I want to avoid. |
||
{ | ||
$components = array_map(array($this, 'normalizeGPSComponent'), $components); | ||
|
||
return intval($components[0]) + (intval($components[1]) / 60) + (floatval($components[2]) / 3600); | ||
} | ||
|
||
/** | ||
* Normalize GPS coordinates components | ||
* | ||
* @param mixed $component | ||
* @return int|float | ||
*/ | ||
protected function normalizeGPSComponent($component) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you unit test this method? Coverage is brought down now, which I want to avoid. |
||
{ | ||
$parts = explode('/', $component); | ||
|
||
return count($parts) === 1 ? $parts[0] : (int) reset($parts) / (int) end($parts); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you unit test this method? Coverage is brought down now, which I want to avoid.