I have imagemagick and rmagick installed so that I can produce images
from code to a file. Can anyone direct me to where I can find
guidance on how to have those images included on a web page (e.g.,
<img src="my_dynamically_generated_image") instead of having them sent
to a file? Thanks for any input.
The first arg to send_data is the blob that is your image, the rest just tell Rails how to format the headers.
You can also look at using data: urls which work like this (but I think IE had troubles so I pulled the data: url out of my own code):
# prefer to use a "data" URL scheme as described in {RFC 2397}[http://www.ietf.org/rfc/rfc2397.txt\]
data_url = "data:image/png;base64,#{Base64.encode64(Sparklines.plot(results,options))}"
tag = %(<img src="#{data_url}" #{attributes}/>)
# respect some limits noted in RFC 2397 since the data: url is supposed to be 'short'
data_url.length <= 1024 && tag.length <= 2100 ? tag : %(<img src="#{ url_for options }" #{attributes}/>)