Internet, UNIX, Video, Leisure…
Photo
WordPress NextGEN Gallery and GPS data
18/01/11
NextGen(eration) Gallery is a WordPress plugin from Alex Rabe. It provides image galleries, albums with great ease of administration.
As said by the author, it fills a gap in WordPress gallery systems.
It can handle « display » templates, which can be added to the plugin Views or simply in your theme. That’s what I’m working on right now for the Photo Theme I’m using in my new Photo Blog.
This way you don’t have to install another plugin and use hooks.
While it’s working well, it still have some features missing.
One of the missing stuffs is beeing able to display GPS data.
My photo blog have Geo-Tagged pictures. I want to be able to display them along with a google map image so my readers can see where it was taken. I also want to display some of the EXIF informations, like lense type, aperture, shutter speed and so on…
While some of them (most) are already handeled by the NextGen gallery, some of them are not.
NextGen Gallery is using the exif_read_data function to get the data from the file like :
Then, the RAW exif datas are separated in arrays. When trying to access the EXIF tags (using get_EXIF), only the part of the array under [EXIF] will be used. In fact this is partly false, as the get_EXIF function also dig under IFD0 and WINXP.
As the GPS data from my Nikon D700 are under the [GPS] array, there is no chance that NextGen gallery sees them even if you use the wordpress filter to add some new EXIF tags.
Then you only have one solution : check in the RAW meta-data or… change NextGen so it can handle them in the EXIF tags stored in the database.
So, my solution is divided in few parts :
- Hardcode some new EXIF tags
- get the GPS data inside get_EXIF
- add a function to parse the GPS data and make them readable/usable by Google Map
Let’s do it :
Hardcode some new EXIF tags
In the file lib/meta.php, change the get_common_meta function so it look like :
-
function get_common_meta() {
-
global $wpdb;
-
-
‘aperture’ => 0,
-
‘credit’ => »,
-
‘camera’ => »,
-
‘caption’ => »,
-
‘created_timestamp’ => 0,
-
‘copyright’ => »,
-
‘focal_length’ => 0,
-
‘iso’ => 0,
-
‘shutter_speed’ => 0,
-
‘flash’ => 0,
-
‘title’ => »,
-
‘altitude’ => »,
-
‘longitude’ => »,
-
‘latitude’ => »,
-
‘timestamp’ => »,
-
‘datestamp’ => »,
-
‘satellites’ => »,
-
‘direction’ => »,
-
‘lense’ => »,
-
‘keywords’ => »
-
);
As you can see, I add all the GPS data, plus « lense », which is just a hook as the EXIF tag for the lense is actualy « UndefinedTag:0xA434″
You can also add the new tags in the i8n translation function
-
function i8n_name($key) {
-
-
‘aperture’ => __(‘Aperture’,‘nggallery’),
-
‘credit’ => __(‘Credit’,‘nggallery’),
-
‘camera’ => __(‘Camera’,‘nggallery’),
-
‘caption’ => __(‘Caption’,‘nggallery’),
-
‘created_timestamp’ => __(‘Date/Time’,‘nggallery’),
-
‘copyright’ => __(‘Copyright’,‘nggallery’),
-
‘focal_length’ => __(‘Focal length’,‘nggallery’),
-
‘iso’ => __(‘ISO’,‘nggallery’),
-
‘shutter_speed’ => __(‘Shutter speed’,‘nggallery’),
-
‘title’ => __(‘Title’,‘nggallery’),
-
‘author’ => __(‘Author’,‘nggallery’),
-
‘tags’ => __(‘Tags’,‘nggallery’),
-
‘subject’ => __(‘Subject’,‘nggallery’),
-
‘make’ => __(‘Make’,‘nggallery’),
-
‘status’ => __(‘Edit Status’,‘nggallery’),
-
‘category’ => __(‘Category’,‘nggallery’),
-
‘keywords’ => __(‘Keywords’,‘nggallery’),
-
‘created_date’ => __(‘Date Created’,‘nggallery’),
-
‘created_time’ => __(‘Time Created’,‘nggallery’),
-
‘position’ => __(‘Author Position’,‘nggallery’),
-
‘city’ => __(‘City’,‘nggallery’),
-
‘location’ => __(‘Location’,‘nggallery’),
-
‘state’ => __(‘Province/State’,‘nggallery’),
-
‘country_code’ => __(‘Country code’,‘nggallery’),
-
‘country’ => __(‘Country’,‘nggallery’),
-
‘headline’ => __(‘Headline’,‘nggallery’),
-
‘credit’ => __(‘Credit’,‘nggallery’),
-
‘source’ => __(‘Source’,‘nggallery’),
-
‘copyright’ => __(‘Copyright Notice’,‘nggallery’),
-
‘contact’ => __(‘Contact’,‘nggallery’),
-
‘last_modfied’ => __(‘Last modified’,‘nggallery’),
-
‘tool’ => __(‘Program tool’,‘nggallery’),
-
‘format’ => __(‘Format’,‘nggallery’),
-
‘width’ => __(‘Image Width’,‘nggallery’),
-
‘height’ => __(‘Image Height’,‘nggallery’),
-
‘flash’ => __(‘Flash’,‘nggallery’),
-
‘latitude’ => __(‘Latitude’,‘nggallery’),
-
‘longitude’ => __(‘Longitude’,‘nggallery’),
-
‘altitude’ => __(‘Altitude’,‘nggallery’),
-
‘lense’ => __(‘Lense’,‘nggallery’),
-
);
get the GPS data inside get_EXIF
Now, every time you insert a new image or re-import the meta-data, the new tags will be asked. We need to change the get_EXIF function so it can find them.
Still in lib/meta.php, go down to the get_EXIF function and change it to :
-
function get_EXIF($object = false) {
-
-
if ( !$this->exif_data )
-
return false;
-
-
-
-
$exif = $this->exif_data[‘EXIF’];
-
-
$meta[‘created_timestamp’] = date_i18n(get_option(‘date_format’) . ‘ ‘ . get_option(‘time_format’), $this->exif_date2ts($exif[‘DateTimeDigitized’]));
-
$meta[‘focal_length’] = $this->exif_frac2dec( $exif[‘FocalLength’] ) . __(‘ mm’,‘nggallery’);
-
$meta[‘iso’] = $exif[‘ISOSpeedRatings’];
-
$meta[‘shutter_speed’] = $this->exif_frac2dec ($exif[‘ExposureTime’]);
-
$meta[‘shutter_speed’] =($meta[‘shutter_speed’] > 0.0 and $meta[‘shutter_speed’] < 1.0) ? ( ’1/’ . round( 1 / $meta[‘shutter_speed’], -1) ) : ($meta[‘shutter_speed’]);
-
$meta[‘shutter_speed’] .= __(‘ sec’,‘nggallery’);
-
}
-
//Bit 0 indicates the flash firing status
-
$meta[‘flash’] = ( $exif[‘Flash’] & 1 ) ? __(‘Fired’, ‘nggallery’) : __(‘Not fired’,‘ nggallery’);
-
-
$meta[‘lense’] = $exif[‘UndefinedTag:0xA434′];
-
}
-
-
// additional information
-
$exif = $this->exif_data[‘IFD0′];
-
-
$meta[‘camera’] = $exif[‘Model’];
-
$meta[‘make’] = $exif[‘Make’];
-
$meta[‘Orientation’] = $exif[‘Orientation’];
-
}
-
// additional GPS information
-
$exif = $this->exif_data[‘GPS’];
-
// send exif data to the function to get GPS on one line
-
$GPS=self::get_Exif_GPS($exif, 1);
-
$meta[‘latitude’] = $GPS[‘latitude’];
-
$meta[‘longitude’] = $GPS[‘longitude’];
-
$meta[‘altitude’] = $GPS[‘altitude’]." metres";
-
$meta[‘timestamp’] = $GPS[‘timestamp’];
-
$meta[‘direction’] = $GPS[‘direction’];
-
$meta[‘satellites’] = $exif[‘GPSSatellites’];
-
$meta[‘datestamp’] = $exif[‘GPSDateStamp’];
-
}
-
}
You can see two things here :
- if the meta asked is « lense », we look for the un-named attribute
- when we are done with EXIF and IFD0, we check in the GPS array
add a function to parse the GPS data and make them readable/usable by Google Map
Now we create the function to re-calculate the GPS coords. Create a function somewhere in the class. A good place is at the end of the lib/meta.php file, just before the last closing bracket.
-
function get_Exif_GPS($exif, $assoc = false) {
-
//get the Hemisphere multiplier
-
$LatM = 1; $LongM = 1;
-
if($exif["GPSLatitudeRef"] == ‘S’) {
-
$LatM = -1;
-
}
-
if($exif["GPSLongitudeRef"] == ‘W’) {
-
$LongM = -1;
-
}
-
-
//get the GPS data
-
$gps[‘LatDegree’]=$exif["GPSLatitude"][0];
-
$gps[‘LatMinute’]=$exif["GPSLatitude"][1];
-
$gps[‘LatgSeconds’]=$exif["GPSLatitude"][2];
-
$gps[‘LongDegree’]=$exif["GPSLongitude"][0];
-
$gps[‘LongMinute’]=$exif["GPSLongitude"][1];
-
$gps[‘LongSeconds’]=$exif["GPSLongitude"][2];
-
$gps[‘Altitude’]=$exif["GPSAltitude"];
-
$gps[‘TimeHour’]=$exif["GPSTimeStamp"][0];
-
$gps[‘TimeMin’]=$exif["GPSTimeStamp"][1];
-
$gps[‘TimeSec’]=$exif["GPSTimeStamp"][2];
-
$gps[‘direction’]=$exif["GPSImgDirection"];
-
-
//convert strings to numbers
-
foreach($gps as $key => $value) {
-
if($pos !== false) {
-
$gps[$key] = $temp[0] / $temp[1];
-
}
-
}
-
-
//calculate the decimal degree
-
$result[‘latitude’] = $LatM * ($gps[‘LatDegree’] + ($gps[‘LatMinute’] / 60) + ($gps[‘LatgSeconds’] / 3600));
-
$result[‘longitude’] = $LongM * ($gps[‘LongDegree’] + ($gps[‘LongMinute’] / 60) + ($gps[‘LongSeconds’] / 3600));
-
$result[‘altitude’] = $gps[‘Altitude’];
-
$result[‘timestamp’] = $gps[‘TimeHour’].‘:’.$gps[‘TimeMin’].‘:’.$gps[‘TimeSec’];
-
$result[‘direction’] = $gps[‘direction’];
-
-
if($assoc) {
-
return $result;
-
}
-
-
}
Conclusion
Re-importing the meta-data of all your pictures should add the new stuffs.
I’v posted in the WordPress forum and asked for this to be added to the NextGen Gallery dev tree. Still have no answer for now. Maybe someone will come with a better code or better idea ?
I also asked for someone to check how GPS data are included in files from other brands as I can only tell for the Nikon’s D700.
New gallery: ete-2010
12/08/10
Vacances d’été 2010 en Provence (04) et dans les Alpes (05)
Lire la suite de l’article »
Introducing new Photo Blog
6/08/10
As I’ve just stopped working for SPI (Casino Barriere and La Française des Jeux), I have to fill my days. And hopefully, I do have a lot of stuffs going on here…
Starting with all my video stuffs and my creation stuffs, like the Remote Follow Focus I’m building with an Arduino.
I also got a video stabilizer (a steadycam) from l’Aigle, which was my past article. It’s a lot of work and practice to get it right and use it right.
As you know I’m also into static photography, and I bought a Nikon D700 last year to use with the lenses I put on the camcorder with the Shoot35 SG-Blade.
I finaly bought two new optics, a Nikon 35-70 macro f2.8 and the new Samyang 14mm manual prime.
This puts me in more photography, and I wanted to be full equiped. I also bought a flashlight (Nissin), a remote shutter and a lightweight carbon tripod from Benro. I just ordered a Nikon compatible GPS to geo-tag the pictures so I can link them easily to Google map…
The final part missing is « what the hell will I do with all this photos… ». I do have the capacity to hold them in the RAID tower I built last year, but that’s not the point. I want to SHARE.
Picasa is fine, so is Fliker… But I’m not in the easy thing, and I want to do more. So I made a « photo » blog.
The real thing is that it’s not a photo-blog. It’s not only photo… But it will evolve, and the goal remain to be focused of photo.
So there you go :
http://blog.lecentre.net
Salon Agriculture 2010
20/03/10
Nikon D700 with Auto-ISO mode, still feat. Mouchette
11/12/09
I tried Auto-ISO with the Aperture First mode.
As I’m using Prime (fixed) lenses, I can play the aperture on the lense (defined as a « no CPU lense, so the D700 knows exactly which aperture I’m in) and have the D700 manage the shutter speed and, if needed, the ISO level, with a max at 3200 ISO.
I also think I’ll have to adjust the dioptrie on the viewfinder…
This is full RAW converted to PNG 150dpi (original is 240dpi).

Nikon D700 first test (feat. Mouchette)
9/12/09

First tests with the Nikon D700 and manual lenses.
With really low light and no knowledge of the camera, see how beautiful Mouchette can be

