Ruby 圖像上傳框架:Dragonfly
Dragonfly 是一個 Ruby gem 用于動態處理 Rails、Sinatra 等框架的圖像上傳。
示例代碼:
如果你想生成縮略圖:
class User < ActiveRecord::Base # model dragonfly_accessor :photo end <%= image_tag @user.photo.thumb('300x200#') # view %>
在 Sinatra 下生成文本圖像
get "/:text" do |text| Dragonfly.app.generate(:text, text, "font-size" => 32).to_response(env) end
生成附件
wav = Dragonfly.app.fetch_url("http://free.music/lard.wav") # GET from t'interwebs mp3 = wav.to_mp3 # to_mp3 is a custom processor uid = mp3.store # store in the configured datastore, e.g. S3 url = Dragonfly.app.remote_url_for(uid) # ===> http://s3.amazon.com/my-stuff/lard.mp3
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!