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'
end

img = 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'
end

img = 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 ;)

5 Responses to “RMagick::RVG : outputting an inline image (or the horrid no decode delegate for this image format `' error)”

  1. Ziggy Says:

    Thanks a lot!!! That helped me =) I was struggling with the same error.

  2. Britt Selvitelle Says:

    Ah! Using this fix for our captcha on Twitter through S3. Fantastic!

  3. Craig Says:

    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.

  4. mike Says:

    @Craig
    Stuff gets out of date pretty fast nowadays it looks :) Thanks for the fix!

  5. Jack Says:

    You definitely just saved me several hours! Thank you!

Leave a Reply