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

| | Comments (1)

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:

  • It allows you to instantly generate a gallery from a directory full of images without having to write a single line of HTML or set any configuration options. To accomplish this, just drop asif.php into a directory, and access the page.
  • It allows you to instantly provide an RSS or Atom feed containing Exif data for any directory full of photos. You could use this for a photoblog, or, really, for instantly creating a photoblog by just dropping your photos into a directory on your server and renaming asif.php to index.php and pointing readers to that directory. Your gallery will automatically update every time you drop a file in the directory, and the RSS/Atom feed will always be fresh.

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.

  • format can be "RSS", "Atom", or "HTML". It defaults to HTML.
  • directory is the path you want to process. Omit the trailing slash on the path. For security reasons, Asif does not, by default, process directories above the one where the Asif script resides. So, if asif.php is in yourdomain.com/photos/galleries/travel/, you can't do something like asif.php?directory=../sports to display photos in /galleries/sports. Instead, put asif.php in the galleries directory, and pass the directory name on the url, like asif.php?directory=sports or asif.php?directory=travel. Get it? Also, if you omit the directory parameter, Asif processes whatever directory it resides in.
  • alldata can be "yes" or "no"/left blank. It defaults to "no." If set to yes, alldata will show all available Exif data for each file. If left blank or set to something other than "yes", it will only show certain common pieces of Exif data: date/time taken, filesize, height/width, f-stop, camera model, ISO, flash, focal length, and user comment. It is not hard to customize the code to add or omit these fields.
  • thumbnails can be "yes" or "no"/left blank. If set to "yes," thumbnails will be generated (if necessary) and displayed. They will be included in the RSS or Atom feeds as img tags, with the src attribute pointing to the URL for the thumbnail, and the link tags pointing to the URL for the full image.

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

1 Comments

chris said:

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]

Leave a comment

About this Entry

This page contains a single entry by ADM published on January 3, 2005 8:22 PM.

Install PHP 5 in a shared server environment, such as Dreamhost.com + was the previous entry in this blog.

Intergalactic Dioxin Poisoning? is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.0