Since a while I'm using iPhoto to manage my photo collection. One thing that kept annoying me was that I had to do manual actions to include selected photo's from iPhoto in my webalbum. Of course you can generate webalbums from iPhoto, but you need to do that over and over again each time you want to add more pictures to your webalbum. The solution I wanted to have was:

  • Import pictures into iPhoto
  • Tag them with keywords
  • Have them appear in my webalbum automatically
    • sorted by date
    • sorted to subject
I only need to maintain iPhoto and the rest is automatic.

I've got this working now for the sorted by date part. What I now do is:

  • In iPhoto I tag the pictures that I want to appear in my webalbum with a special keyword (webalbum)
  • Scheduled a cronjob that periodically:
    • Runs a ruby script sortImages.rb [note: this is an updated version of the previous script, the description in the blog post is not 100% accurate anymore] which parses the iPhoto AlbumData.xml file. This scripts selects all pictures with the 'webalbum' keyword and exports these to a directory structure in which they are sorted by year/month. (The script first checks if the AlbumData.xml is changed since the last run to prevent unnecessary work.)
    • If the ruby script sortImages.rb [see previous note] found any changes, kick of the webalbum application to update the webalbum (I'm using JAlbum, but you can use any webablum application that takes a directory structure as input).

The shell script is really simple.

ruby sortByDate.rb webalbum /tmp/webalbum '/path/to/AlbumData.xml'

if [ $? -eq 0 ]; then
cd /opt/JAlbum
java -Xmx256M -Djava.awt.headless=true -jar JAlbum.jar
-projectFile webalbum.jap -appendImages
The sortImages.rb [see previous note] script takes 3 arguments:
  • The keyword that identifies the pictures to include in the webalbum.
  • The directory to which the pictures should be copied. In this directory new directories per year/month will be created.
  • The path to the iPhoto AlbumData.xml file

Writing the Ruby script was easy, it was the first time i really tried to do something with Ruby and I got it done pretty quick.... although I bet there is some improvement possible. Feel free to let me know ;-) The actual tricky parts were:

  • Figure out the structure of the AlbumData.xml file
  • Transform the DateAsTimerInterval element from the AlbumData.xml file into the date the picture was taken.

Next plan is to create a script that generates a directory structure using the other keywords set on the pictures. For example, group all pictures tagged with 'webalbum' and 'vacataion' and 'friends'. Sounds simple, but need to come up with some logic to be able to create a multi level structure where level one contains the images with only the 'vacation' keyword, level 2 has 'vacation' and 'friends' etc. What do I do with pictures that could end up in multiple parts of the tree?

*** Update ***

I just tested if this solution still works with iPhoto '09 and it works perfectly.