Jan 08 9

Creating a photoblog with WordPress

While I updated shutterclicks to the new layout I switched it over to WordPress from Pixelpost. While Pixelpost wasn't exactly unsuitable for what I wanted, its comment handling and generally very ugly codebase had me going nuts whenever I needed to do any maintenance on the site.

I'm now using a very bare bones install of WordPress with the Yet-Another-PhotoBlog plugin. And SpamKarma for spam filtering (which works much better than Akismet in my experience). I'll probably look into other plugins to use on shutterclicks as well once I get all of the Pixelpost content moved over to WordPress. I used the import script from Shifting Pixel to do the base work.

However, it had problems in importing the images and embedding them in the correct post so I need to do some manual work as well. Which is to the better, since I'd need to fiddle around with the images to get them working with YAPB anyhow.

While YAPB has all of the documentation needed to get it going, it still needs some thought before it is fully functional. Unless of course you let it do all the necessary code injection of the pictures (which I naturally don't). For example, there's no template tag to insert the picture itself without any thumbnailing so you have to use some code for it. The following does the trick well enough:

<img src="<?php echo $post-/>image->uri ?>" width="< ?php echo $post->image->width ?>" height="< ?php echo $post->image->height ?>" />

Also, the EXIF output is quite horrible and needs formatting to be more readable. Well, that's all IMHO ;). But I've never liked to see EXIF data displayed as it is on many websites in the very mathematic way (with lots of precision in the numbers etc). Rather I like to see it similar to the camera display (and how Lightroom shows it). So I wrote the following code to customize the EXIF output:

	if ($exif = ExifUtils::getExifData($post->image)) {
		echo '
<ul class="exif">';
		if (!empty($exif['model'])) {
			echo '
<li>' . $exif['model'] . '</li>
 
 ';
		}
		if (!empty($exif['exposureTime'])) {
			$time = $exif['exposureTime'];
			$i = strpos($time, '(');
			$j = strpos($time, ')', $i);
			$time = substr($time, $i + 1, $j - $i - 1);
   			$t = explode('/', $time, 2);
            if (empty($t[1]))
               	echo "
<li>$time s</li>
 
";
            elseif ($t[1] == 1)
                echo "
<li>$t[0] s</li>
 
";
            else
           		echo '
<li>' . $t[0] . '/' . $t[1] . "&#x00A0;s</li>
 
 ";
		}
		if (!empty($exif['fnumber'])) {
			echo '
<li>' . $exif['fnumber'] . '</li>
 
 ';
		}
		if (!empty($exif['isoEquiv']))
			echo '
<li>ISO&#x00A0;' . $exif['isoEquiv'] . '</li>
 
 ';
		if (!empty($exif['exposureBias'])) {
			$ev = $exif['exposureBias'];
			$i = strpos($ev, '(');
			$j = strpos($ev, ')', $i);
			$ev = substr($ev, $i + 1, $j - $i - 1);
			$ev = explode('/', $ev, 2);
            if ($ev[0] == 0)
	            $ev = '0';
   			elseif ($ev[1] >= 10)
           		$ev = $ev[0]/10 . '/' . $ev[1]/10;
   			else
           		$ev = $ev[0] . '/' . $ev[1];
           	echo "
<li>$ev&#x00A0;EV</li>
 
 ";
		}
		if (!empty($exif['focalLength'])) {
			$mm = $exif['focalLength'];
			$i = strpos($mm, ' ');
			$mm = substr($mm, 0, $i);
			$mm = round($mm, 0);
			echo "
<li>$mm&#x00A0;mm</li>
 
 ";
		}
		if (!empty($exif['flashUsed']))
			echo '
<li>Flash:&#x00A0;' . $exif['flashUsed'] . '</li>
 
';
		echo '</ul>
 
';
	}

That code still needs some work, I'm not satisfied with how the exposure bias is displayed (3/3 when I'd like +1 in those cases). But at least it's a step in the right direction.