HowTo: Geodata from exif into image

Phoca Gallery - image gallery extension
chilly_bang
Phoca Member
Phoca Member
Posts: 13
Joined: 09 Dec 2008, 01:51
Location: Berlin
Contact:

HowTo: Geodata from exif into image

Post by chilly_bang »

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

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);
	}
2. administrator/components/com_phocagallery/models/phocagallery.php
Befor lines

Code: Select all

//clean alias name (no bad characters)
		$data['alias'] = PhocaGalleryText::getAliasName($data['alias']);
we add

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;
		}
3. administrator/components/com_phocagallery/models/phocagallerym.php
After line

Code: Select all

$datam['imgorigsize'] 	= PhocaGalleryFile::getFileSize($datam['filename'], 0);
we add

Code: Select all

$coords=PhocaGalleryFile::getGeoCoords($datam['filename']);
						$datam['longitude']		= $coords['longitude'];
						$datam['latitude']		= $coords['latitude'];
						$datam['zoom']			= 13;	
4. administrator/components/com_phocagallery/front/models/category.php
Befor lines

Code: Select all

$row =& $this->getTable('phocagallery');
		
		// Bind the form fields to the Phoca gallery table
we add

Code: 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;
		}
5. components/com_phocagallery/models/category.php
Befor lines

Code: Select all

	$row =& $this->getTable('phocagallery');
		
		// Bind the form fields to the Phoca gallery table
we add

Code: 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;
		}
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;)
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49150
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: HowTo: Geodata from exif into image

Post by Jan »

Hi, thank you very much for this improvement.

Jan
If you find Phoca extensions useful, please support the project
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49150
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: HowTo: Geodata from exif into image

Post by Jan »

Implemented with minor changes (plus added the code to user model) in 3.0.1

Thank you, Jan
If you find Phoca extensions useful, please support the project
nhtim
Phoca Member
Phoca Member
Posts: 13
Joined: 14 May 2011, 10:26

Re: HowTo: Geodata from exif into image

Post by nhtim »

I think this is what I want for version 2.8 for Joomla 1.5! :) I thought this was already in version 2.8. Jan..... is this what needs to be done for version 2.8?
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49150
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: HowTo: Geodata from exif into image

Post by Jan »

Hi, for now I found time to implement it only to 3.0.1 :-( :-(

Jan
If you find Phoca extensions useful, please support the project
nhtim
Phoca Member
Phoca Member
Posts: 13
Joined: 14 May 2011, 10:26

Re: HowTo: Geodata from exif into image

Post by nhtim »

OK, this answered my question in the other post. :( Sorry to hear it it could not be implemented in 2.8 :( I was so hoping to use the phoca gallery for my site. There is another extension that has this function, but I like the layout of phoca gallery and admin so much better. Thank you for your patience in answering all my questions Jan! :)
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49150
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: HowTo: Geodata from exif into image

Post by Jan »

Ok :(
If you find Phoca extensions useful, please support the project
nhtim
Phoca Member
Phoca Member
Posts: 13
Joined: 14 May 2011, 10:26

Re: HowTo: Geodata from exif into image

Post by nhtim »

Jan,

Do you think that if I followed what chilly_bang posted at the start of this message into Phoca Gallery 2.8 for Joomla 1.5... that it might give me what I am looking for, at least temporarily until you fully implement it into the version for 1.5? I must say that it appears that you care about Phoca Gallery very much, and I appreciate your hard work!!!
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 49150
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: HowTo: Geodata from exif into image

Post by Jan »

Hi, yes, I have implemented the feature followed by this guide.

Jan
If you find Phoca extensions useful, please support the project
nhtim
Phoca Member
Phoca Member
Posts: 13
Joined: 14 May 2011, 10:26

Re: HowTo: Geodata from exif into image

Post by nhtim »

HI Jan,

Thanks to you and chilly_bang! I have gotten the geotagging working on my website! Now my visitors will have a much more enjoyable experience viewing the photos from my trip. Hey Jan, I do not know where you live in the Czech Republic, but I will be in Ostrava and Prague the beginning of September. Send me an email and maybe we can meet up and I will buy you a beer! :)

Tim
Post Reply