xfxf/dragonfly


License: MIT

Language: Ruby


Dragonfly

Dragonfly is a Rack framework for on-the-fly image handling.

Ideal for using with Ruby on Rails (2.3 and 3), Sinatra and all that gubbins.

However, Dragonfly is NOT JUST FOR RAILS, and NOT JUST FOR IMAGES!!

IMPORTANT: if you're running a version between 0.7.0 and 0.9.12, please update to at least 0.9.14 for a security update details here

For the lazy Rails user...

Gemfile:

gem 'rack-cache', :require => 'rack/cache'
gem 'dragonfly', '~>0.9.15'

Initializer (e.g. config/initializers/dragonfly.rb):

require 'dragonfly/rails/images'

Migration:

add_column :albums, :cover_image_uid,  :string
add_column :albums, :cover_image_name, :string  # Optional - only if you want urls
                                                # to end with the original filename

Model:

class Album < ActiveRecord::Base
  image_accessor :cover_image            # 'image_accessor' is provided by Dragonfly
                                         # this defines a reader/writer for cover_image
  # ...
end

View (for uploading via a file field):

<% form_for @album, :html => {:multipart => true} do |f| %>
  ...
  <%= f.file_field :cover_image %>
  ...
<% end %>

NB: REMEMBER THE MULTIPART BIT!!!

You can avoid having to re-upload when validations fail with

<%= f.hidden_field :retained_cover_image %>

remove the attachment with

<%= f.check_box :remove_cover_image %>

assign from some other url with

<%= f.text_field :cover_image_url %>

and display a thumbnail (on the upload form) with

<%= image_tag @album.cover_image.thumb('100x100').url if @album.cover_image_uid %>

View (to display):

<%= image_tag @album.cover_image.url %>
<%= image_tag @album.cover_image.thumb('400x200#').url %>
<%= image_tag @album.cover_image.jpg.url %>
<%= image_tag @album.cover_image.process(:greyscale).encode(:tiff).url %>
...etc.

The above relies on imagemagick being installed. Dragonfly doesn't depend on it per se, but the default configuration 'dragonfly/rails/images' uses it. For alternative configurations, see below.

If using Capistrano with the above, you probably will want to keep the cache between deploys, so in deploy.rb:

namespace :dragonfly do
  desc "Symlink the Rack::Cache files"
  task :symlink, :roles => [:app] do
    run "mkdir -p #{shared_path}/tmp/dragonfly && ln -nfs #{shared_path}/tmp/dragonfly #{release_path}/tmp/dragonfly"
  end
end
after 'deploy:update_code', 'dragonfly:symlink'

Sinatra, CouchDB, Mongo, Rack, S3, custom storage, processing, and more...

Dragonfly is not just for Rails - it's primarily a Rack app, so you can use it as a standalone app, or with Sinatra, Merb, etc.

It's highly customizable, and works with any data type (not just images).

For more info, consult the DOCUMENTATION

Add-ons

For third-party add-ons, see the Add-ons wiki

Issues

Please use the github issue tracker if you have any issues.

Suggestions/Questions

Google group dragonfly-users

Credits

Copyright

Copyright (c) 2009-2010 Mark Evans. See LICENSE for details.

Project Statistics

Sourcerank 3
Repository Size 4.81 MB
Stars 0
Forks 0
Watchers 2
Open issues 0
Dependencies 22
Contributors 34
Tags 74
Created
Last updated
Last pushed

Top Contributors See all

Henry Phan Philip Arndt Aidan Feldman Oliver Legg Kennon Ballou Frederick Cheung Ryan Verner Michael Rykov Jon Rowe Malcolm Locke Cyril Mougel Andre Fonseca Federico Gonzalez Jeremy Seitz Jordan Elver João Maia Kazuaki Takase Niall Mullally Nicholas Henry Sam Rawlins

Recent Tags See all

v0.9.15-4 April 28, 2015
v0.9.15-3 April 28, 2015
v0.9.15-1 April 23, 2015
v1.0.7 August 26, 2014
v1.0.6 August 22, 2014
v1.0.5 May 15, 2014
v1.0.4 April 11, 2014
v1.0.3 January 28, 2014
v1.0.2 December 20, 2013
v1.0.1 November 28, 2013
v1.0.0 November 24, 2013
v0.9.15 May 04, 2013
v0.8.6 March 26, 2013
v0.9.14 February 13, 2013
v0.9.13 January 30, 2013

Something wrong with this page? Make a suggestion

Last synced: 2016-05-28 08:43:59 UTC

Login to resync this repository