LayerVault has just open-sourced a library they have created to read Photoshop PSD files in Ruby. It allows you to parse the whole Photoshop document, inspect individual layers, even output a flattened image. Check out their post