[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Embed Images in eruby

Horacio Sanson

10/2/2006 10:09:00 AM


I want to read an image from disk, modify it with rmagick (scale) and display
it in an HTML IMG tag but without saving the modified image to disk.

Is there a way to send the Image object directly to the IMG tag??

Something like:

<%
require "RMagick"
include Magick

img = Image.read("image.jpg").first

## Do stuff to img.... like scale it down....
%>

<img src="<%=img.to_blob%>"></img>


regards,
Horacio

4 Answers

Jano Svitok

10/2/2006 11:19:00 AM

0

On 10/2/06, Horacio Sanson <horacio.sanson@gmail.com> wrote:
>
> I want to read an image from disk, modify it with rmagick (scale) and display
> it in an HTML IMG tag but without saving the modified image to disk.
>
> Is there a way to send the Image object directly to the IMG tag??
>
> Something like:
>
> <%
> require "RMagick"
> include Magick
>
> img = Image.read("image.jpg").first
>
> ## Do stuff to img.... like scale it down....
> %>
>
> <img src="<%=img.to_blob%>"></img>

See http://redhanded.hobix.com/inspect/sparklinesForMinima...

Horacio Sanson

10/2/2006 1:21:00 PM

0


Cool.... I took me 3 mins to get what I wanted....

Here is the code I used:


<%
require 'base64'
require 'RMagick'
require 'cgi'

include Magick

img = Image.read('test.jpg').first

def build_url(data)
data = Base64.encode64(data).delete("\n")
return "data:image/jpeg;base64,#{CGI.escape(data)}"
end
%>

<div>
<img src="<%=build_url(img.to_blob)%>"></img>
</div>


This displays the image in the page with no problems....
~


??? 02 10? 2006 20:33?Martin Coxall ????????:
> > See http://redhanded.hobix.com/inspect/sparklinesForMinima...
>
> I don't know what "Bumsparks" are, but they sound frightfully exciting.
>
> Martin

David Vallner

10/2/2006 8:14:00 PM

0

Horacio Sanson wrote:
> I want to read an image from disk, modify it with rmagick (scale) and display
> it in an HTML IMG tag but without saving the modified image to disk.
>
> Is there a way to send the Image object directly to the IMG tag??
>
> Something like:
>
> <%
> require "RMagick"
> include Magick
>
> img = Image.read("image.jpg").first
>
> ## Do stuff to img.... like scale it down....
> %>
>
> <img src="<%=img.to_blob%>"></img>
>

http://www.ietf.org/rfc/r...

Warning. Base64, madness, and death lie that way.

Well, not really, but I don't think it works in IE.

David Vallner

Esad Hajdarevic

10/2/2006 9:43:00 PM

0

Horacio Sanson wrote:

> This displays the image in the page with no problems....

Beware that here the data is encoded within the URI, so you are limited
on your browsers' maximal URI length. I've read somewhere that Opera
accepts URIs of maximal length 4kb, so that may be the upper limit for
the image size.

See: http://en.wikipedia.org/wik...

Greetings,

Esad