HowTo: Geodata from exif into image
Posted: 17 Jun 2011, 14:17
Problem: phoca read exif data but geodata must be set into each image only on manual way.
We wish:
first, that every image, if it has geodata in its exif, get geocoordinates automagically after upload, and
second, that all automatically geotagged images get geozoom level 13.
Solution:
We must change 5 files:
1. administrator/components/com_phocagallery/libraries/phocagallery/file/file.php
we declare function that we use after on all places, where we upload images. At the end of file add
2. administrator/components/com_phocagallery/models/phocagallery.php
Befor lines
we add
3. administrator/components/com_phocagallery/models/phocagallerym.php
After line
we add
4. administrator/components/com_phocagallery/front/models/category.php
Befor lines
we add
5. components/com_phocagallery/models/category.php
Befor lines
we add
Save and enjoy! After upload or multiple upload of images from backend and frontend add you images to categories and open: each image, that has geodata inside of its exif has lon and lat filled in. Don't forget to backup befor any changes;)
We wish:
first, that every image, if it has geodata in its exif, get geocoordinates automagically after upload, and
second, that all automatically geotagged images get geozoom level 13.
Solution:
We must change 5 files:
1. administrator/components/com_phocagallery/libraries/phocagallery/file/file.php
we declare function that we use after on all places, where we upload images. At the end of file add
Code: Select all
function getGeoCoords($filename){
$fileOriginal = PhocaGalleryFile::getFileOriginal($filename);
$exif = @exif_read_data($fileOriginal, 0, true);
$GPSLatDeg = explode('/',$exif['GPS']['GPSLatitude'][0]);
$GPSLatMin = explode('/',$exif['GPS']['GPSLatitude'][1]);
$GPSLatSec = explode('/',$exif['GPS']['GPSLatitude'][2]);
$GPSLonDeg = explode('/',$exif['GPS']['GPSLongitude'][0]);
$GPSLonMin = explode('/',$exif['GPS']['GPSLongitude'][1]);
$GPSLonSec = explode('/',$exif['GPS']['GPSLongitude'][2]);
$lat = $GPSLatDeg[0]/$GPSLatDeg[1]+
($GPSLatMin[0]/$GPSLatMin[1])/60+
($GPSLatSec[0]/$GPSLatSec[1])/3600;
$long = $GPSLonDeg[0]/$GPSLonDeg[1]+
($GPSLonMin[0]/$GPSLonMin[1])/60+
($GPSLonSec[0]/$GPSLonSec[1])/3600;
// $exif['GPS']['GPSLatitudeRef'] SHIROTA: N=+; S=-
// $exif['GPS']['GPSLongitudeRef'] DOLGOTA: E=+; W=-
if($exif['GPS']['GPSLatitudeRef'] == 'S'){$lat=$lat*(-1);}
if($exif['GPS']['GPSLongitudeRef'] == 'W'){$long=$long*(-1);}
return array('latitude'=>$lat,'longitude'=>$long);
}Befor lines
Code: Select all
//clean alias name (no bad characters)
$data['alias'] = PhocaGalleryText::getAliasName($data['alias']);Code: Select all
if($data['longitude'] == '' || $data['latitude'] == ''){
$coords=PhocaGalleryFile::getGeoCoords($data['filename']);
}
if ($data['longitude'] == '' ){
$data['longitude'] = $coords['longitude'];
}
if ($data['latitude'] == '' ){
$data['latitude'] = $coords['latitude'];
//$data['videocode']=print_r($teststring,true);
}
if ($data['zoom'] ==''){
$data['zoom'] = 13;
}After line
Code: Select all
$datam['imgorigsize'] = PhocaGalleryFile::getFileSize($datam['filename'], 0);Code: Select all
$coords=PhocaGalleryFile::getGeoCoords($datam['filename']);
$datam['longitude'] = $coords['longitude'];
$datam['latitude'] = $coords['latitude'];
$datam['zoom'] = 13; Befor lines
Code: Select all
$row =& $this->getTable('phocagallery');
// Bind the form fields to the Phoca gallery tableCode: Select all
if((!isset($data['longitude']) || (isset($data['longitude']) && $data['longitude'] =='')) ||
(!isset($data['latitude']) || (isset($data['latitude']) && $data['latitude'] ==''))
){$coords=PhocaGalleryFile::getGeoCoords($data['filename']);}
if (!isset($data['longitude']) || (isset($data['longitude']) && $data['longitude'] =='')){
$data['longitude'] = $coords['longitude'];
}
if (!isset($data['latitude']) || (isset($data['latitude']) && $data['latitude'] =='')){
$data['latitude'] = $coords['latitude'];
}
if (!isset($data['zoom']) || (isset($data['zoom']) && $data['zoom'] =='')){
$data['zoom'] = 13;
}Befor lines
Code: Select all
$row =& $this->getTable('phocagallery');
// Bind the form fields to the Phoca gallery tableCode: Select all
if((!isset($data['longitude']) || (isset($data['longitude']) && $data['longitude'] =='')) ||
(!isset($data['latitude']) || (isset($data['latitude']) && $data['latitude'] ==''))
){$coords=PhocaGalleryFile::getGeoCoords($data['filename']);}
if (!isset($data['longitude']) || (isset($data['longitude']) && $data['longitude'] =='')){
$data['longitude'] = $coords['longitude'];
}
if (!isset($data['latitude']) || (isset($data['latitude']) && $data['latitude'] =='')){
$data['latitude'] = $coords['latitude'];
}
if (!isset($data['zoom']) || (isset($data['zoom']) && $data['zoom'] =='')){
$data['zoom'] = 13;
}