RMagick::RVG : outputting an inline image (or the horrid no decode delegate for this image format `' error)
Ruby 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 ;)
October 3rd, 2007 at 5:07 pm
Thanks a lot!!! That helped me =) I was struggling with the same error.
November 7th, 2007 at 12:34 pm
Ah! Using this fix for our captcha on Twitter through S3. Fantastic!
December 3rd, 2007 at 12:34 pm
I think this is out of date: I couldn't set img.format. However, when I said
img.to_blob {self.format = "jpg"}
It worked fine. So, presumably, this bug has been fixed.
December 3rd, 2007 at 12:40 pm
@Craig
Stuff gets out of date pretty fast nowadays it looks :) Thanks for the fix!
March 28th, 2008 at 10:42 pm
You definitely just saved me several hours! Thank you!