Import photo GPS exif to database and use in posts
-
Hello all,
I recently started using EXIF data on my blog under the photoblog category and decided I want to use the GPS exif as well (example in the post The Red Box). In case anyone else wants to do this, I thought I’d post the code. I’ll just put the code here and hope that those who want to use it know how to. There will be a post on my blog in a few days (Monday) explaining it a little more (Geo EXIF data in WordPress).
In wp-admin/includes/image.php in the function starting at line 231, change the array to,
$meta = array( 'aperture' => 0, 'credit' => '', 'camera' => '', 'caption' => '', 'created_timestamp' => 0, 'copyright' => '', 'focal_length' => 0, 'iso' => 0, 'latitude' => 0, 'latitude_ref' => '', 'longitude' => 0, 'longitude_ref' => '', 'shutter_speed' => 0, 'title' => '', );
Then after
if (!empty($exif['ISOSpeedRatings'])) $meta['iso'] = $exif['ISOSpeedRatings'];
add
if (!empty($exif['GPSLatitude'])) $meta['latitude'] = $exif['GPSLatitude'] ; if (!empty($exif['GPSLatitudeRef'])) $meta['latitude_ref'] = trim( $exif['GPSLatitudeRef'] ); if (!empty($exif['GPSLongitude'])) $meta['longitude'] = $exif['GPSLongitude'] ; if (!empty($exif['GPSLongitudeRef'])) $meta['longitude_ref'] = trim( $exif['GPSLongitudeRef'] );
That causes the GPS info to be imported into the database when a photo is uploaded (not including the altitude, because I only needed a map location).
The code I use within my theme to show the location info is in this text file.
If you have suggestions for improving the code I’d love to hear them.
- The topic ‘Import photo GPS exif to database and use in posts’ is closed to new replies.