RMagick::RVG : outputting an inline image (or the horrid no decode delegate for this image format `' error)
Thursday, March 8th, 2007Ruby is all nice and all, but some things are just either very poorely documented or just don't work very seamlessly sometimes. I have spend over an hour today trying to identify what is going on with RMagick::RVG not wanting to output an inline image for me.
The error I was getting was:
no decode delegate for this image format `'
And the code was as simple as contents of my brain in the early morning:
Magick::RVG.dpi = 72
rvg = Magick::RVG.new(320, 320).viewbox(0,0,320,320) do |canvas|
canvas.background_fill = 'red'
endimg = rvg.draw
send_data img.to_blob,
:filename => "woohoo.png",
:disposition => 'inline',
:quality => 90,
:type => 'image/png'
Everything seems to be fine and as I'm setting the image type in the to_blog thingy, I somehow assume there should be no problems decoding the image. Well I was wrong! In order to get rid of the bloody no decode delegate for this image format `' you have to specify the image format you want to image to be in, manually.
Behold the magic!
Magick::RVG.dpi = 72
rvg = Magick::RVG.new(320, 320).viewbox(0,0,320,320) do |canvas|
canvas.background_fill = 'red'
endimg = rvg.draw
img.format = "png" #FORGET THIS LINE AND DIE A HORRIBLE DEATH!! :)
send_data rvg.draw.to_blob,
:filename => "woohoo.png",
:disposition => 'inline',
:quality => 90,
:type => 'image/png'
Well.. that's it :) Hopefully it will help someone to save an hour or two ;)


