# Dynamic images

**URL:** <https://www.ruby-forum.com/t/dynamic-images/95196>\
**Category:** Rails\
**Created:** [December 4, 2005, 10:05pm UTC](https://www.ruby-forum.com/t/dynamic-images/95196 "2005-12-04T22:05:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kitesurfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kitesurfer](https://www.ruby-forum.com/u/kitesurfer)\
**Post date:** [December 4, 2005, 10:05pm UTC](https://www.ruby-forum.com/t/dynamic-images/95196/1 "2005-12-04T22:05:15Z")

</div>

Hi,

I have a controller that uses gruff to create a chart. I would like  
to be able to return this image back to the view without having to dump  
the image to disk first. Does anyone have sample code for the controller  
and view to handle such a problem ?

Thank you all !!

---

<div class="post-metadata">

**Author:** ![kitesurfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kitesurfer](https://www.ruby-forum.com/u/kitesurfer)\
**Post date:** [December 4, 2005, 10:51pm UTC](https://www.ruby-forum.com/t/dynamic-images/95196/2 "2005-12-04T22:51:10Z")

</div>

On Dec 4, 2005, at 1:05 PM, KiteSurfer KiteSurfer wrote:

> Does anyone have sample code for the controller  
> and view to handle such a problem ?

Create a specific action to generate the image and send it with  
[send\_data](http://api.rubyonrails.com/classes/ActionController/).

–Steve

Streaming.html#M000041

---

<div class="post-metadata">

**Author:** ![kitesurfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kitesurfer](https://www.ruby-forum.com/u/kitesurfer)\
**Post date:** [December 5, 2005, 12:27am UTC](https://www.ruby-forum.com/t/dynamic-images/95196/3 "2005-12-05T00:27:40Z")

</div>

Thanks Steve !! That helps but…

send\_data will forward me to a new page. I want to be able to display  
the chart within the existing page ?

I guess I am not really sure how to formulate the send\_data from within  
the page ??

---

<div class="post-metadata">

**Author:** ![kitesurfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kitesurfer](https://www.ruby-forum.com/u/kitesurfer)\
**Post date:** [December 5, 2005, 12:53am UTC](https://www.ruby-forum.com/t/dynamic-images/95196/4 "2005-12-05T00:53:08Z")

</div>

On Dec 4, 2005, at 3:27 PM, KiteSurfer KiteSurfer wrote:

> I guess I am not really sure how to formulate the send\_data from  
> within  
> the page ??

Create a separate dedicated action, just for the image, then within  
whatever page you just link to that like a regular image.

HTH,  
Steve

---

<div class="post-metadata">

**Author:** ![kitesurfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kitesurfer](https://www.ruby-forum.com/u/kitesurfer)\
**Post date:** [December 5, 2005, 1:23am UTC](https://www.ruby-forum.com/t/dynamic-images/95196/5 "2005-12-05T01:23:12Z")

</div>

Got it !! Thanks Steve you tough me something cool today…

Now do you know how to accomplish the same thing using an ajax call ?

---

<div class="post-metadata">

**Author:** ![kitesurfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kitesurfer](https://www.ruby-forum.com/u/kitesurfer)\
**Post date:** [December 5, 2005, 5:16am UTC](https://www.ruby-forum.com/t/dynamic-images/95196/6 "2005-12-05T05:16:08Z")

</div>

I’m not sure if it’s possible, as ajax only deals with text based  
data. However, you might be able to send an ![]() tag that loads a  
dynamic image…

---

<div class="post-metadata">

**Author:** ![kitesurfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kitesurfer](https://www.ruby-forum.com/u/kitesurfer)\
**Post date:** [December 5, 2005, 5:12am UTC](https://www.ruby-forum.com/t/dynamic-images/95196/7 "2005-12-05T05:12:05Z")

</div>

On Dec 4, 2005, at 4:23 PM, KiteSurfer KiteSurfer wrote:

> Now do you know how to accomplish the same thing using an ajax call ?

Someone else will have to chime in to help you with that. 🙂 Good  
luck.

–Steve

---

<div class="post-metadata">

**Author:** ![kitesurfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kitesurfer](https://www.ruby-forum.com/u/kitesurfer)\
**Post date:** [December 5, 2005, 6:08am UTC](https://www.ruby-forum.com/t/dynamic-images/95196/8 "2005-12-05T06:08:43Z")

</div>

hmmm, a noob ruby question. After I gem install gruff, I opened the irb  
to  
try require ‘rubygems’ and require ‘gruff’, and then I got two false.  
Why?  
I’m using ruby 1.8.3 on WinXP. I also put the sample code from gruff’s  
home  
page into a controller. It seems rails still didn’t know the name of  
‘gruff’.

Thanks,

Sky

---

<div class="post-metadata">

**Author:** ![kitesurfer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kitesurfer](https://www.ruby-forum.com/u/kitesurfer)\
**Post date:** [December 5, 2005, 7:21am UTC](https://www.ruby-forum.com/t/dynamic-images/95196/9 "2005-12-05T07:21:12Z")

</div>

Steve : No problem. Thanks again for the help !!  
I think I need to dig in google map apis to try to figure this one out.  
It  
must be achievable using javascript.

Sky: I have successfully installed Gruff on both linux and windows. For  
both of these you need to have ImageMagick or GraphMagick installed. You  
also need Rmagick. Somehow it was not clear from the docs that gruff had  
these dependencies when I started to look at it…

Hope this helps…
