ruby on rails - Feather an image from code -
is there way feather image code? (if don't know feathering is, check this out - i'm not using dirty language)
i know professional design applications photoshop can this, users upload images site , display them in feathered fashion. (now there's sentence don't hear every day)
i can see 2 ways. in both ways prepare transparent png image "feather" effect. combine image original , requested result.
the solution little more complicated in case of dynamic sizes - basic principle same.
css way
in case can make operation on client side. prepare transparent png mask makes "feather" effect - use photoshop/gimp create it.
let's suppose named mask "feather.png" , original image named "source.jpg". can use html code
<div style="width: 200px;height: 200px; background: url(/images/source.jpeg)"> <img width="200" height="200" src="/images/feather.png" /> </div>
server side
in case i'd use paperclip gem. uses magic imagemagick library. think of photoshop on command line (little bit exaggerating there not much)
in model:
class avatar < activerecord::base has_attached_file :image, :styles => { :feather => { :geometry => "200x200", :format => :jpg }, :normal => { :geometry => "200x200", :format => :jpg } }, :convert_options => { :feather => "#{rails.root.join('public/images/feather-200x200.png')} -composite" } end
and thats it. in code when you'd use "feathered" image should use:
<%= image_tag avatar.image.url(:feather) %>
or :normal non-feathered version of it.
all conversion , transformation done assignment:
avatar = avatar.new # file... avatar.image = open(....) # or maybe form... avatar.image = params[:...] # not saves avatar db runs image transformations avatar.save!
Comments
Post a Comment