Dragonfly Tips & Tricks

Dragonfly is Ruby Rack-based gem for on-the-fly processing - suitable for image uploading in Rails, Sinatra and much more!

And it is awesome. You can transform an already uploaded image into any size thumbnail, image formats and perform most ImageMagick operations.

Image effects


Original Image

<%= image_tag @gallery.image.thumb("200x200").url %>

Picture

Polaroid

<%= image_tag @gallery.image.thumb("200x200").png.convert("-background #666666 +polaroid").url %>

Picture

Border

<%= image_tag @gallery.image.thumb("200x200").png.convert("-bordercolor #000000 -border 10").url %>

Picture

Border + Shadow

<%= image_tag @gallery.image.thumb("200x200").png.convert("-bordercolor white -border 13 ( +clone -background black -shadow 80x3+2+2 ) +swap -background white -layers merge +repage").url %>

Picture

Custom color inversion

<%= image_tag @gallery.image.thumb("200x200").png.convert("-colorspace HSL -channel Luminance -negate").url %>

Picture

Distort

<%= image_tag @gallery.image.thumb("200x200").png.convert("-matte -virtual-pixel transparent -distort Perspective '0,0,0,0 0,120,0,90 90,0,90,25 90,90,90,65'").url %>

Picture

Add Label

<%= image_tag @gallery.image.thumb("200x200").png.convert("-gravity south -fill white -annotate 0 'Copyright: © Author'").url %>

Picture

Polor Distortion

<%= image_tag @gallery.image.thumb("200x200").png.convert("-virtual-pixel HorizontalTile -background transparent -distort Polar 0").url %>

Picture

Sample Images


<%= image_tag Dragonfly[:images].generate(:plasma, 200, 200, :png).url %>

Picture

Custom Jobs


# config/initializers/dragonfly.rb
Dragonfly[:images].configure do |c|
  c.job :polaroid do |size|
    encode :png
    convert "-background #666666 +polaroid"
  end
end  

<%= image_tag @gallery.image.thumb("200x200").polaroid %>

Picture