Rmagick - Incorporating dynamic images

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

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 B. http://agileconsultingllc.com
[email protected]
+1 513-295-4739
Skype: rob.biedenharn

Wow!! I didn’t know this was going to be that
involved. I guess that’s why I was unable to
find anything on google. Thanks for the input.

  ... doug