Search code examples
rubyrmagickpadrino

How can I render an image with Padrino?


I need to create image files on-the-fly in my controller with RMagick and send them to browser. Looks like it's very simple, but I can't find a way. I've tried just simply render them, but it fails due to data is binary. I've also tried to use send_data, but Padrino says it doesn't know about such method.

So, what have I missed? How can I solve this problem?


Solution

  • according to sinatra api you don't need this anymore.

    get :image, with: id, provides: :png do
      img = Image.find(params[:id])
      img.binary_data_or_so
    end
    

    basically is the same of:

    get '/send_binarydata' do
      content_type 'image/png'
      \x01\x02\x03
    end