This plugin provides a way to use iPhoto to manage photos and videos for your Rails application.
iPhoto '08 and '09
script/plugin install git://github.com/hsume2/iphoto-library.git
Requires plist gem
sudo gem install plist
Requires mini_magick gem for on-demand thumbnails
script/generate iphoto_library LibraryPath Server
to create the configuration and migrations necessary
Resets iPhoto data in database rake iphoto:reset Load iPhoto library AlbumData.xml into database rake iphoto:load Updates iPhoto data incrementally into database rake iphoto:update
You can create thumbnails on demand at RAILS_ROOT/public/photos.
photo = Photo.find(3) photo.on_demand(720,720) # /photos/3/720x720.jpg
Creates a 720 by 720 thumbnail the first time the method is called. Subsequent calls will return the path to previously created thumbnails.
Thumbnail paths and image paths are automatically swizzled to the server specified in iphoto.yml photo = Photo.first photo.thumb_path # Thumbnail used in iPhoto photo.image_path # Image stored in iPhoto Library (could be in Modified, Originals, Data) movie = Movie.first movie.thumb_path # Auto-generated thumbnail used in iPhoto movie.image_path # The video itself movie.movie_path # same as image_path
Anywhere in your rails app you can call IphotoLibrary.path IphotoLibrary.server IphotoLibrary.albumdata_path to retrieve the settings stored in iphoto.yml
Be sure to close iPhoto, before running tasks, so changes to the library are written to file (AlbumData.xml)
In your rails app root, execute
script/generate iphoto_library /Users/YourUser/Pictures/iPhoto\ Library/ static.yourdomain.com to create the configuration file necessary, and rake db:migrate to create the tables, and
rake iphoto:load to load events (rolls), photos, and videos into the database.
Depending on your configuration, you may want to server the photos straight froms rails (easier, less setup). In your rails root, run
ln -s /whereever/you/have/your/iPhoto\ Library/ /public/library
And when running the iphoto_library generator, instead of
Use Apache to staticly serve the photos straight from your iPhoto Library. Add something like this to your virtual host conf.
<VirtualHost *:80> ServerAdmin email@example.com DocumentRoot “/Users/YourUser/Pictures/iPhoto Library/” # <- Your iPhoto Library ServerName static.yourdomain.com
<Directory “/Users/YourUser/Pictures/iPhoto Library/”> # No Options Indexes, we don't want anyone/anything crawling around AllowOverride All Order deny,allow Allow from all </Directory> </VirtualHost>
Try this safer Apache configuration. <VirtualHost *:80> ServerAdmin firstname.lastname@example.org DocumentRoot “/Library/WebServer/Documents” # <- Doesn't matter, maybe try a 404 page? ServerName static.yourdomain.com Alias /Data “/Users/Family/Pictures/iPhoto Library/Data”
<Directory “/Users/Family/Pictures/iPhoto Library/Data”> AllowOverride All Order deny,allow Allow from all </Directory>
Alias /Modified “/Users/Family/Pictures/iPhoto Library/Modified”
<Directory “/Users/Family/Pictures/iPhoto Library/Modified”> AllowOverride All Order deny,allow Allow from all </Directory>
Alias /Originals “/Users/Family/Pictures/iPhoto Library/Originals”
<Directory “/Users/Family/Pictures/iPhoto Library/Originals”> AllowOverride All Order deny,allow Allow from all </Directory> </VirtualHost>
Currently only supports one iPhoto Library
What about loading assets into the database as well?
Or other forms of storage?
Copyright © 2009 Henry Hsu, released under the MIT license