January 03, 2005

Introducing Asif: Convert EXIF data to RSS, Atom, or HTML

When you take a picture with a digital camera, most cameras store some data along with the picture, such as the date and time you took the photo, whether you used the flash, the focal length, the f-stop, and the make and model of the camera. This information is called EXIF data.

I thought it would be useful to be able to automatically publish this data in an RSS or Atom feed, so I wrote a PHP script to do just that.

My script, named Asif, will process a directory containing JPEGs and output an HTML, RSS, or Atom feed containing some or all of the Exif data for each picture, as well as (optionally) a thumbnail version of the picture.

See it in action:

This demo processes the files in this directory. The thumbnails are generated dynamically, as needed. (The good pictures are from manyhighways.com.)

Asif has two primary benefits:

The output format is controlled by the user. Simply append the name of the format to the URL, and you get what you asked for. So, http://yourdomain.com/photos/asif.php?format=rss gets you RSS, and asif.php?format=atom gets you Atom. Omitting the format parameter produces HTML.

Similarly, the user controls whether to display thumbnails: asif.php?thumbnails=yes displays them. Omitting that parameter omits them. If thumbnails are requested, they will be included in the RSS or Atom feeds as well.

Asif can handle any directory path you pass to it on the URL. So, asif.php?format=rss&directory=sample will process the web directory called "sample". Directory paths are relative to the path of the script. So, asif.php?format=rss&directory=sample/travel/nyc will go down three directories and display the images. Omitting the directory directive tells Asif to display the data for the current directory.

Cameras often store far more Exif data than is really useful, such as manufacturers' notes that are essentially encoded gibberish. For this reason, Asif by default will only show you certain Exif fields. However, if you wish to see all available Exif data for a file, pass the directive &alldata=yes on the URL, and Asif will return everything it finds in the file.

By default, Asif produces valid XHTML 1.0, valid RSS 2.0, and valid Atom .3. As long as you don't have any weird stuff mixed into your Exif data, it should always validate. The appearance of the HTML is controlled entirely via CSS, which of course you can customize.

Requirements

Asif requires PHP5, compiled with the GD libraries and with the directive --enable-exif. However, I believe only one line of code -- a call to scandir() -- needs to be rewritten to work in PHP4. (I included the alternate PHP4-compliant code in the comments.) If you don't have PHP5 installed on your server, I discuss how to do so in another post.

Installation

  1. Get the source code.
  2. Get the CSS file asif.css so you can control the HTML formatting.
  3. Install both files in a directory on your webserver, and rename asif.phps to asif.php.

It will be instantly ready to use, assuming the GD and Exif libraries are working on your server. If desired, change the constants defined at the top of the file to meet your needs.

Asif is free software and covered by the GPL.

Using Asif

Asif is controlled by passing parameters on the URL. These parameters are described above and in the source code. Available parameters are: format, directory, alldata, and thumbnails.

Support

If you have questions or comments, please post them below.

Disclaimer

I am not the world's greatest PHP programmer. The code is inefficient, it may not work, and it may expose your server to security risks. Be sure to read all of the comments in the code, and secure your own webserver properly. Use this software at your own risk. It is offered without warranty or assumption of liability.

Update (2005-02-09): I figured out how to generate RSS feeds using PHP5's DOM support, which I recommend using. When I get some time, I will update this script to use the DOM.

categories: Software
posted by adm at January 3, 2005 08:22 PM

Trackback Pings

TrackBack URL for this entry:
http://www.thousandrobots.com/mt/mt-tb.cgi/752

Comments

http://feedvalidator.org/check?url=http://thousandrobots.com/projects/asif/sample.php?directory=sample&thumbnails=yes&format=rss

your feed does not parse :-(

-C-

[sorry....it looks like the validator is somehow getting the HTML content instead of the XML....even though a regular browser gets the XML/RSS. not sure what's going on there. i'll take a look at it when i get a minute. in the meantime, i've come up with a much better way of accomplishing this using PHP5 and DOM. See thousandrobots.com for details. -adm]

Posted by: chris at March 29, 2005 05:37 PM

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?