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>