On Mar 29, 2007, at 11:59 AM, doug wrote:
>
> Hi --
>
> 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.
>
> ... doug
Take a look at the sparklines gem to see all the goodness, but this
fragment from the generated sparklines_controller should get you
started:
send_data( Sparklines.plot( ary, params ),
:disposition => ''inline'',
:type => ''image/png'',
:filename => "spark_#{params[:type]}.png" )
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}/>)
-Rob
Rob Biedenharn http://agileconsultingllc.com
Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
+1 513-295-4739
Skype: rob.biedenharn
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---