Skip to content
This repository has been archived by the owner on Jan 29, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Added exif latitude and longitude.
  • Loading branch information
milesj committed Jan 18, 2015
1 parent 3d9286b commit d77820f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
30 changes: 12 additions & 18 deletions src/Transit/File.php
Expand Up @@ -182,8 +182,8 @@ public function exif(array $fields = array()) {
'date' => 'DateTime',
'iso' => 'ISOSpeedRatings',
'focal' => 'FocalLength',
'latitude' => 'GPSLatitude',
'longitude' => 'GPSLongitude'
'latitude' => 'GPSLatitude',
'longitude' => 'GPSLongitude'
);

if ($file->supportsExif()) {
Expand All @@ -192,11 +192,16 @@ public function exif(array $fields = array()) {
$value = '';

if (!empty($data[$find])) {
if ($key == 'latitude' || $key == 'longitude'){
$value = $file->dmstodec($data[$find][0], $data[$find][1], $data[$find][2]);
} else {
$value = $data[$find];
}
// Convert DMS (degrees, minutes, seconds) to decimals
if ($key === 'latitude' || $key === 'longitude'){
$deg = $data[$find][0];
$min = $data[$find][1];
$sec = $data[$find][2];
$value = $deg + ((($min * 60) + $sec) / 3600);

} else {
$value = $data[$find];
}
}

$exif[$key] = $value;
Expand Down Expand Up @@ -597,17 +602,6 @@ public function toArray() {
public function toString() {
return $this->path();
}

/**
* Converts DMS ( Degrees / minutes / seconds )
* to decimal format longitude / latitude
* @return float
*/
function dmstodec($deg,$min,$sec) {

return $deg+((($min*60)+($sec))/3600);

}

/**
* Cache the results of a callback.
Expand Down
12 changes: 9 additions & 3 deletions tests/Transit/FileTest.php
Expand Up @@ -102,7 +102,9 @@ public function testExif() {
'fnumber' => '45/10',
'date' => '2013:06:07 11:32:22',
'iso' => 100,
'focal' => '100/10'
'focal' => '100/10',
'latitude' => '',
'longitude' => ''
), $file->exif());

$file = new File(TEMP_DIR . '/magic-mime-verify.js');
Expand All @@ -115,7 +117,9 @@ public function testExif() {
'fnumber' => '',
'date' => '',
'iso' => '',
'focal' => ''
'focal' => '',
'latitude' => '',
'longitude' => ''
), $file->exif());
}

Expand Down Expand Up @@ -327,7 +331,9 @@ public function testToArray() {
'exif.fnumber' => '',
'exif.date' => '',
'exif.iso' => '',
'exif.focal' => ''
'exif.focal' => '',
'exif.latitude' => '',
'exif.longitude' => ''
), $this->object->toArray());
}

Expand Down
8 changes: 6 additions & 2 deletions tests/Transit/Transformer/Image/ExifTransformerTest.php
Expand Up @@ -24,7 +24,9 @@ public function testLandscape() {
'fnumber' => '',
'date' => '',
'iso' => '',
'focal' => ''
'focal' => '',
'latitude' => '',
'longitude' => ''
);

// 1
Expand Down Expand Up @@ -104,7 +106,9 @@ public function testPortrait() {
'fnumber' => '',
'date' => '',
'iso' => '',
'focal' => ''
'focal' => '',
'latitude' => '',
'longitude' => ''
);

// 1
Expand Down

0 comments on commit d77820f

Please sign in to comment.