# Rmagick - Incorporating dynamic images

**URL:** <https://www.ruby-forum.com/t/rmagick-incorporating-dynamic-images/90533>\
**Category:** Rails\
**Created:** [March 29, 2007, 6:01pm UTC](https://www.ruby-forum.com/t/rmagick-incorporating-dynamic-images/90533 "2007-03-29T18:01:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [March 29, 2007, 6:01pm UTC](https://www.ruby-forum.com/t/rmagick-incorporating-dynamic-images/90533/1 "2007-03-29T18:01:29Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [March 29, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/rmagick-incorporating-dynamic-images/90533/2 "2007-03-29T20:27:07Z")

</div>

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](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](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid  
+1 513-295-4739  
Skype: rob.biedenharn

---

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [March 29, 2007, 10:27pm UTC](https://www.ruby-forum.com/t/rmagick-incorporating-dynamic-images/90533/3 "2007-03-29T22:27:00Z")

</div>

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
```
