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

1st of May – Valea Ierii

The long break I took from riding my motorcycle finally came to an end today. I made a small trip with some friends (they were with cars), to a beautiful location not far from Cluj. I must say it was truly delightful and made me dream again of journeys with no worries and no destinations.

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

Javascript VIN (car chassis) number validation

Well this isn`t php, is a JavaScript code that validates a car chassis number (VIN). I expect comments on improving the code, as JavaScript isn`t my strong point, I know just as much as any php web developer should know.

var vinletters=new Array();
vinletters[1]="AJ";
vinletters[2]="BKS";
vinletters[3]="CLT";
vinletters[4]="DMU";
vinletters[5]="ENV";
vinletters[6]="FW";
vinletters[7]="GPX";
vinletters[8]="HY";
vinletters[9]="RZ";

//--------------12345678901234567
var vinweight= "8765432T098765432";

function valvin(serie){
	if(serie.length == 17){
		suma = 0;
		for (i=0 ; i < serie.length; i++) {
			nextchar = serie.charAt(i);
			for (j in vinletters){
				if(vinletters[j].indexOf(nextchar) != -1){
					nextchar = j;
				}
			}
			val = parseInt(nextchar);
			weight = vinweight.charAt(i);
			if(weight == "T"){
				weight = 10;
			}else{
				weight = parseInt(weight);
			}
			suma += val * weight;
		}
		controlchar = suma % 11;
		if(controlchar == 10) controlchar = "X";
		if(controlchar == serie.charAt(8)){
			return true;
		}else{
			return false;
		}
	}else{
		return false;
	}
	return false;
}

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.