Orby Online

Reinventing ourselves since 2001

Developing LitenessPhoto: a photoblog theme for Wordpress

Posted on June 13, 06

In the process of creating a Wordpress photoblog theme called LitenessPhoto for the photography section of this website, I’ve had to learn the ins and outs of PHP’s EXIF extension and GD library of image functions.

Exif display example

For the uninitiated, EXIF data is information stored in an image file that can specify what kind of camera was used to take a digital picture, exposure information, image resolution, and quite a bit more. For a good overview, check out this Wikipedia article. The GD library allows PHP to create, manipulate, and pull information from photos.

I created Orby Photo with the intention of being able to automatically display the exposure time, f/stop, exposure bias, focal length, and ISO speed of any pictures taken with my camera; all without any work needing to be done by me (use of the EXIF extension). I also want the ability to display an album picture (usually a combination of some of the photos from an album) created by myself, or have one created automatically by PHP if one created by me is not present in a specified folder (use of the GD library).

Although this was easy on paper, a number of wrenches and baby sledges were thrown into the mix at various points during and after development.

For instance, getting the f/stop value should be as easy as $aperture = $exif[FNumber];. However, it seems that the presence of the $exif[FNumber] variable is dependent upon which version of iPhoto I’m using. This forces me to use $exif[ApertureValue] whenever $aperture = $exif[FNumber]; isn’t present.

For reasons I won’t go into here, these numbers are not the same. Instead, $exif[FNumber] is equal to to the square root of two raised to the power of the value $exif[ApertureValue]. Because we’re now dealing with irrational numbers, the computed f/stop value doesn’t always come out to the correct f/stop value of the image. Because of this, a series of if/else statements must be present in order to correct for situations where the computed value is not equal to the actual f/stop value (e.g. 21.9 instead of 22). Because wider f/stop values sometimes include one decimal place, I couldn’t simply round to the closes whole number, or f/2.8 would become f/3.

Instead of a simple output statement for the f/stop value, the code quickly ballooned to:

if (isset($exif[FNumber]))
	$aperture = $exif[FNumber];
	$aperture = round(pow(sqrt(2),
		convert_fraction($exif[ApertureValue], true)),1);

if ($aperture == ‘21.9′)
	$aperture = 22;
elseif ($aperture == ‘14.1′)
	$aperture = 14;
elseif ($aperture == ‘20.1′)
	$aperture = 20;
elseif ($aperture == ‘24.9′)
	$aperture = 25;

$output .= “$tabs<h3>:Aperture</h3>:\\n$tabs<p>:f/”.$aperture.”</p>:\\n”;

I hope to finish up development of the theme soon, and then begin the process of packaging it up so other Wordpress users can easily add it to their sites.