Embed Images in eruby

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

%>

regards,
Horacio

On 10/2/06, Horacio S. [email protected] wrote:

    include Magick

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

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

%>

See http://redhanded.hobix.com/inspect/sparklinesForMinimalists.html

See http://redhanded.hobix.com/inspect/sparklinesForMinimalists.html

I don’t know what “Bumsparks” are, but they sound frightfully exciting.

Martin

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

%>

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

æ??æ??æ?¥ 02 10æ?? 2006 20:33ã?Martin C. ã?ã??はæ?¸ãã¾ã?ã?:

Horacio S. 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/wiki/Data_Uri

Greetings,

Esad

Horacio S. wrote:

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

Do stuff to img… like scale it down…

%>

http://www.ietf.org/rfc/rfc2397.txt

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

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

David V.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs