Hi,
Ok so if anyone is interested here''s how I managed to do it.
1- Install RMagick
2- In the controller where you want to generate the pic do something
like:
# GET /pics/1
# GET /pics/1.xml
def show
@pic = Pic.find(params[:id])
Magick::RVG.dpi = 90
rvg = Magick::RVG.new(10.cm, 3.cm).viewbox(0,0,1000,300) do |canvas|
canvas.background_fill = ''black''
canvas.text(250, 150, @pic.name
).styles(:font_family=>''Verdana'',
:font_size=>55, :fill=>''white'')
canvas.circle(5, 250, 170).styles(:fill=>''red'')
canvas.rect(997, 297).styles(:fill=>''none'',
:stroke=>''blue'')
end
rvg.draw.write(''text01.jpg'')
before = Magick::Image.read("text01.jpg").first
blob = before.to_blob
#puts blob
@base64image = Base64.encode64(blob)
puts "base64"
puts @base64image
respond_to do |format|
format.html # show.html.erb
format.svg { render :action => "svg.rhtml", :layout =>
false }
format.xml { render :xml => @pic }
end
end
# GET /pics/new
# GET /pics/new.xml
def new
@pic = Pic.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @pic }
end
end
3- Now you can generate an SVG image of the @base64image variable. That
image contains the name of a picture stored in the DB:
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 10 10">
<image xlink:href="data:image/png;base64,<%= @base64image %>"
width="10" height="5"/>
</svg>
------------
I think that was all I needed to do. So now when I go to
http://127.0.0.1.:3000/pics/3.svg I can see a generated pic with the
name of that pic.
Extra- The trick to be able to serve SVG is explained in the next
thread:
http://www.ruby-forum.com/topic/149851#new
------------
So basically I can now create a graphical representation of the model.
It was easy, if anyone has any optimization ideas to the process above
feel free to suggest.
Cheers!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---