Dragonfly: Image Handling For Champions

Created at: 12.03.2010 01:39, source: Rails Inside , tagged: plugins

dragonfly.jpgDragonfly is a new(-ish!) ruby gem for handling images and other content in Ruby web apps (including Rails). “What – another one?!”.. I hear you exclaim. While using Dragonfly in Rails is similar to using, say, Paperclip, a significant difference is that images are generated on the fly, as opposed to when uploaded. This at first sounds like just a small detail, but it opens us up to a wide range of new possibilities..

First, thumbnail sizes are no longer specified in the model, but in the view. So when designs (i.e. image sizes) change, we simply make the change…in the view. Previously we’d change the model, then reprocess all of the already uploaded images. Furthermore, it is now trivial to have a custom avatar cropping for each user, or blog posts with different image sizes, etc. This would be difficult if thumbnails were created on upload.

Rack Off

Dragonfly isn't so much for Rails, but for anything using Rack. It can be used as a standalone Rack application, or inserted as middleware into any Rack stack, e.g. with Sinatra, Merb, etc. Using with Rails is designed to be super-easy though, so anyone used to using Paperclip and friends should find it fairly intuitive.

Custom and Excise

Custom data stores / processors / encoders / analysers, etc., can be created to suit your needs. It is designed to be as configurable as possible, while using sensible defaults for those who can’t be bothered with the details. Any type data can be served – not just images – though not all data suits the on-the-fly paradigm.

Cache and Carry

Dragonfly is meant to be used behind a cache-proxy such as Varnish, Squid or Rack::Cache, so that while the first request may take some time, subsequent requests should be super-quick!

Take a look at the bamboo blog post for an introduction, or else check out the code and the documentation

[post by] Mark Evans, a web developer at New Bamboo who writes Ruby and Javascript by day and spends the rest of the time running around like a headless chicken and playing the guitar.

Post to Twitter Tweet This Post