# Displaying a base64-encoded image within an rhtml template

**URL:** <https://www.ruby-forum.com/t/displaying-a-base64-encoded-image-within-an-rhtml-template/129470>\
**Category:** Rails\
**Created:** [February 18, 2008, 9:56pm UTC](https://www.ruby-forum.com/t/displaying-a-base64-encoded-image-within-an-rhtml-template/129470 "2008-02-18T21:56:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/848f3c/32.png) [@kyle](https://www.ruby-forum.com/u/kyle)\
**Post date:** [February 18, 2008, 9:56pm UTC](https://www.ruby-forum.com/t/displaying-a-base64-encoded-image-within-an-rhtml-template/129470/1 "2008-02-18T21:56:13Z")

</div>

I’m working on generating FedEx labels for quick & easy shipping.  
FedEx returns the label as a base64-encoded string. Assuming that  
‘match’ is the base64 string containing the label data, here is what I  
have to display the image:

send\_data image, :filename =\> ‘fedex\_shipping\_label.png’, :type =\>  
‘image/png’, :disposition =\> ‘inline’

That works fine, but I’d like to be able to set some html/css  
parameters on it so that it prints at 200dpi, 4x6 inches (the RMagick  
‘resample’ method wasn’t working for me). I don’t really want to save  
the label as a file, either. Is there a way to send a variable to the  
template (e.g., @image) so that it gets rendered as an image?

Thank you!

-Kyle

---

<div class="post-metadata">

**Author:** ![kyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/848f3c/32.png) [@kyle](https://www.ruby-forum.com/u/kyle)\
**Post date:** [February 19, 2008, 11:29am UTC](https://www.ruby-forum.com/t/displaying-a-base64-encoded-image-within-an-rhtml-template/129470/2 "2008-02-19T11:29:18Z")

</div>

On 18 Feb 2008, at 20:55, Kyle wrote:

> parameters on it so that it prints at 200dpi, 4x6 inches (the RMagick  
> ‘resample’ method wasn’t working for me). I don’t really want to save  
> the label as a file, either. Is there a way to send a variable to the  
> template (e.g., @image) so that it gets rendered as an image?  
> Well you can do  
> ![](data:image/jpeg;base64,base_64_data_here)  
> So presumably, just ![]() would do the trick

Fred

>

---

<div class="post-metadata">

**Author:** ![kyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/848f3c/32.png) [@kyle](https://www.ruby-forum.com/u/kyle)\
**Post date:** [February 19, 2008, 10:15pm UTC](https://www.ruby-forum.com/t/displaying-a-base64-encoded-image-within-an-rhtml-template/129470/3 "2008-02-19T22:15:59Z")

</div>

Thank you! I had never seen the data type in an image element. After  
a couple of stupidity checks, it appears to be working very well.

Thank you again.

-Kyle

On Feb 19, 4:28 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![kyle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/848f3c/32.png) [@kyle](https://www.ruby-forum.com/u/kyle)\
**Post date:** [February 19, 2008, 10:57pm UTC](https://www.ruby-forum.com/t/displaying-a-base64-encoded-image-within-an-rhtml-template/129470/4 "2008-02-19T22:57:43Z")

</div>

Be aware this does not work in IE 6 or 7…

See this: [Dean Edwards: Base64 Encoded Images for Internet Explorer](http://dean.edwards.name/weblog/2005/06/base64-ie/)  
and this: [Dean Edwards: Base64 Encoded Images for Internet Explorer (sexy version)](http://dean.edwards.name/weblog/2005/06/base64-sexy/)
