I am trying to convert an image in a rails application from SVG to PNG. ImageMagick didnโt work for me, because Heroku was unable / unable to update IM at this time. I am testing some ideas for using RSVG2 / Cairo in dev, but have run into an obstacle.
I can easily convert and save SVG to PNG as follows:
#svg_test.rb require 'debugger' require 'rubygems' require 'rsvg2' SRC = 'test.svg' DST = 'test.png' svg = RSVG::Handle.new_from_file(SRC) surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, 800, 800) context = Cairo::Context.new(surface) context.render_rsvg_handle(svg) surface.write_to_png(DST)
But it only allows me to write PNG files. In the application, I need to be able to generate them on the fly, and then send them to the client browser as data. And I canโt understand how to do this, or even if it is supported. I know that I can call surface.data to get the raw data, but I don't know enough about image formats to know how to get this as PNG.
thanks
ruby-on-rails png
Dave sanders
source share