Cluj Napoca

Today while I was out I had taken these two shoots. The quality is poor, pictures were taken with phone at twilight, and have some amount of granulation. But I like this place, I would love to see as more places like this as possible in this city. Also, a nice picture with transalp :D

Cluj Napoca

Cluj Napoca

In the fields

Geotagging from image EXIF data in WordPress

Displaying imagine location in wordpress using their gps coords proved to be not as easy as I initially thought, but it is something I wanted to get done from some time now, so I decided to get down on it. I have chosen to use geotag plugin for its capability to read exif data from images spread through a post and nicely locate them on a google map, among other stuff.

Unfortunately, after uploading few images I discovered that the cool functionality of searching photos with gps exif data and displaying their location on map was not working. That was because the images displayed don`t have any exif data stored in the file, as wordpress automatically  stripes it down on image upload, but not before data is read so it can be stored serialized in postmeta table from db. Instead of altering wordpress core files to modify this behavior, I preferred to find a different approach and try using the meta info already stored into database. But the problem is that wp save only some tags from exif, and GPS information in not among them, so first step is to add the following filter to the wp_read_image_metadata hook:

add_filter('wp_read_image_metadata', 'saveGeoExif','',3);

function saveGeoExif($meta,$file) {
    $exif = @exif_read_data($file);

    if (isset($exif['GPSLatitude'])){
        $meta['GPSLatitude'] = $exif['GPSLatitude'];
    }
    if (isset($exif['GPSLatitudeRef'])){
        $meta['GPSLatitudeRef'] = trim($exif['GPSLatitudeRef']);
    }
    if (isset($exif['GPSLongitude'])){
        $meta['GPSLongitude'] = $exif['GPSLongitude'] ;
    }
    if (isset($exif['GPSLongitudeRef'])){
        $meta['GPSLongitudeRef'] = trim($exif['GPSLongitudeRef']);
    }

    if (isset($exif['GPSAltitudeRef'])){
        $meta['GPSAltitudeRef'] = trim($exif['GPSLongitudeRef']);
    }
    if (isset($exif['GPSAltitude'])){
        $meta['GPSAltitude'] = trim($exif['GPSLongitudeRef']);
    }
    if (isset($exif['GPSTimeStamp'])){
        $meta['GPSTimeStamp'] = $exif['GPSLongitudeRef'];
    }
    if (isset($exif['GPSDOP'])){
        $meta['GPSDOP'] = $exif['GPSLongitudeRef'];
    }
    if (isset($exif['GPSImgDirectionRef'])){
        $meta['GPSImgDirectionRef'] = trim($exif['GPSLongitudeRef']);
    }
    if (isset($exif['GPSImgDirection'])){
        $meta['GPSImgDirection'] = trim($exif['GPSLongitudeRef']);
    }

	return $meta;
}

This will save all GPS information into database upon image upload.

Next we need to search all the photo attachments belonging to a post, calculate their coordinates and extract image url, and then pass them to geotag plugin.

add_filter("the_content", 'getGeodataFromMeta');

function fractionResult($fraction){
    list($sup, $sub) = explode('/', $fraction);
    if(floatval($sub) != 0){
        return $sup / $sub;
    }else{
        return 0;
    }
}

function getCoord($fractional, $ref){
    $coord = 0;
    if(is_array($fractional)){
        $coord = fractionResult($fractional[0]) + fractionResult($fractional[1]) / 60 + fractionResult($fractional[2]) / 3600;
    }
    if($ref == "S" || $ref == "W"){
        $coord = -$coord;
    }
    return $coord;
}

function getGeodataFromMeta($content){
    global $photoMetaCoords;
    $postId = get_the_ID();
    $attachments = get_posts('post_type=attachment&post_mime_type=image&post_parent=' . $postId);

    foreach ($attachments as $attachment){
        $meta = wp_get_attachment_metadata($attachment->ID);
        if(isset($meta['image_meta']['GPSLatitude'])){
            $lat = getCoord($meta['image_meta']['GPSLatitude'], $meta['image_meta']['GPSLatitudeRef']);
            $long = getCoord($meta['image_meta']['GPSLongitude'], $meta['image_meta']['GPSLongitudeRef']);

            $imageUrl = wp_get_attachment_image_src($attachment->ID, array(133, 133));
            $photo = array(
                'lat' => $lat,
                'lon' => $long,
                'uri' => $imageUrl[0]
            );

            $photoMetaCoords[] = $photo;
        }
    }
    return $content;
}

Last thing we need to do in order to get all this to work is to alter a bit geotag plugin, so it will also load the images from $photoMetaCoords array. In function getGeotagsFromPhotos() add the following line before if (empty($geotags)) {return null;} else… :

$geotags = array_merge($geotags, $photoMetaCoords);
$photoMetaCoords = array();

Also at the begining of getGeotagsFromPhotos() function change:

global $post;

to

global $post, $photoMetaCoords;

That`s it!

All the code presented here should be added in functions.php or in geotag.php (except the last line which should always go in geotag.php, of course :) ).

turda

flowers

flowers

pfff

Truly inspirational

Well I`m sure that most of you saw this video and heard about Matt.  A regular 32-year-old guy who suddenly realized that life can offer a lot more than what he was asking for. This is his first video, who made him very popular over YouTube. I can`t describe the feelings I have when I see thees movies… amazing.

In 2008 he released a second one.

It really makes me shiver.