我正在尋找一個寶石或解決方案來在控制器響應中生成圖像。如何在Rails中響應PNG或JPG並從HTML生成圖像?
這將是很好,如果有可能的控制器,這樣做:
respond_to :html, :png
def show
...
respond_to do |format|
format.html
format.png { ??? } # some html to png converter
end
end
當png
格式要求的響應處理與模板:
#show.png.haml
%h1
Some title
%p
Some content
結果應該是一個圖像。
我知道約pdf
世代解決方案PDFKit,prawn我正在尋找圖像生成。
有沒有人知道工作解決方案/示例?任何起點將非常感激。
@floor,感謝響應。我的不好,我的問題不是很清楚。問題更多的是關於從html生成圖片的問題。現在我澄清它。 – Voldy 2011-02-27 21:31:37
您需要將您的html轉換爲圖片?看上去 – fl00r 2011-02-27 21:42:48
再次感謝。有一個'wkhtmltopdf'的寶石:https://github.com/siuying/websnap。這裏是一個例子http://www.freezzo.com/2010/07/29/how-to-create-pdfs-and-images-from-your-website-in-rails/ – Voldy 2011-02-27 21:49:46