Reading Picasa captions in PHP

Ok, it’s going to get technical.

Although I’ve recently bought Photoshop Elements, Picasa used to be my photo browser of choice (in fact it still is as I get used to Photoshop). Therefore when I wanted an easier way to add photos to the BMTG website, I developed it with Picasa in mind.

Apart from the site generating its own thumbnails, it also gets its description from the embedded Picasa data. I found out the data after reading on the PHP site about looking at EXIF and other image data and writing a program to display it all – this revealed the Picasa caption field.

However, it did seem to have an anomaly in that it ended with a null character. I therefore coded around this. Unfortunately 1 with Picasa 3, this appears to have been fixed and so recently described photos are being truncated on my site. It’s not too much of a hassle, though, to detect for this. The code I use is as follows…

list($width, $height) = getimagesize($full_filename, $info);
$iptc = iptcparse($info["APP13"]);
$description = $iptc["2#120"][0];
if (ord(substr($description,-1))==0) {
   $description=substr($description,0,-1);
}

Simply populate $full_filename with, well, the filename of the image. At the end of it all the Picasa caption will be in $description and the image width and height in $width and $height.

The last line of the code is where I’m working around the null character at the end of the caption (or not).

  1. depending how you look at it[]

Posted by David Artiss

Enterprise Happiness Engineer for the WordPress VIP team at Automattic. Gamer, film lover and general fan of all things Marvel, Star Trek and Star Wars. Failed comedian. Writer for The Big Tech Question. World's Greatest Grandma.

Talk to me!

This site uses Akismet to reduce spam. Learn how your comment data is processed.