brisruby-dragonfly-slides



brisruby-dragonfly-slides

0 0


brisruby-dragonfly-slides


On Github elliotthilaire / brisruby-dragonfly-slides

gem 'dragonfly'

@elliotthilaire

Why I chose to use it

  • No up front processing
  • Suitable for Sinatra and Rails
  • General enough to use for anything

How it works

  • Datastore
  • Processors, Generators, Analysers
  • Rack server

Example

image = Dragonfly.app.fetch('gallery/angry-centipede.jpg')

 => <Dragonfly::Job ... >


thumbnail = image.thumb('300x300').watermark

 => <Dragonfly::Job ... >


url = thumbnail.url

 => "/media/W1siZiIsImZlYXR1cmVkL2FuZ3J5LWNlbnRpcGVkZS5qcGciXSxbInAiLCJ0aHVtYiI
 sIjMwMHgzMDAiXSxbInAiLCJ3YXRlcm1hcmsiXV0"

Dragonfly::Job

<Dragonfly::Job app=:default, 
steps=[fetch("gallery/angry-centipede.jpg"),
  process(:thumb, "300x300")], process(:watermark), 
content=<Dragonfly::Content temp_object=<Dragonfly::TempObject data="" >>,
steps applied:0/3 >

Set up

require 'dragonfly'

Dragonfly.app.configure do

  # Set a secret used to add a SHA sum to the generated URLS.
  secret 'I code in PHP when no one is looking.'

  # Load plugins
  plugin :imagemagick

end

use Dragonfly::Middleware
run Sinatra::Application
rails generate dragonfly

config/initializers/dragonfly.rb

Models

class Photo

  attr_accessor :image_uid  # 'gallery/angry-centipede.jpg'

  extend Dragonfly::Model
  dragonfly_accessor :image
  ...
end
...
<img src="<%= @photo.image.thumb('300x200#').url %>" />
...

Custom processor

Dragonfly.app.configure do

  ...

  processor :upside_down do |content, *args|

      content.shell_update do |old_path, new_path|  
        "pdftk #{old_path} cat 1-endsouth output #{new_path}" 
      end

  end

  ...

end

Version Change

0.9.15 (2013-05-04)

1.0.0 (2013-11-24)

Resources

Documentation: markevans.github.io/dragonfly

Blog post: www.new-bamboo.co.uk/blog/2010/01/13/dragonfly/

Wiki: https://github.com/markevans/dragonfly/wiki/Dragonfly-add-ons

Google Group: https://groups.google.com/forum/#!topic/dragonfly-users

THE END