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 %>
Polaroid
<%= image_tag @gallery.image.thumb("200x200").png.convert("-background #666666 +polaroid").url %>
Border
<%= image_tag @gallery.image.thumb("200x200").png.convert("-bordercolor #000000 -border 10").url %>
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 %>
Custom color inversion
<%= image_tag @gallery.image.thumb("200x200").png.convert("-colorspace HSL -channel Luminance -negate").url %>
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 %>
Add Label
<%= image_tag @gallery.image.thumb("200x200").png.convert("-gravity south -fill white -annotate 0 'Copyright: © Author'").url %>
Polor Distortion
<%= image_tag @gallery.image.thumb("200x200").png.convert("-virtual-pixel HorizontalTile -background transparent -distort Polar 0").url %>
Sample Images
<%= image_tag Dragonfly[:images].generate(:plasma, 200, 200, :png).url %>
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 %>
Written by Rahul Trikha
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#