Reputation: 1118
I am trying to render an animated Gif from a controller action like this:
send_file data, type: 'image/gif', disposition: 'inline'
where data is equal to a blob output from rmagick. The image renders fine, but it is not animated like I expect. I think it has something to do with the rmagick image generation, and not the send_file, because if I instead write the animated gif to disk from rmagick, and render that, it works like expected.
So, onto my rmagick code...
gif = Magick::ImageList.new
gif.from_blob *frames # frames is an array of image blobs
gif.delay = delay if delay
gif.iterations = iterations if iterations
gif.scene = scene if scene
gif.ticks_per_second = ticks_per_second if ticks_per_second
gif.to_blob
This returns a blob, but I'm not sure if it is returning a single frame, or if it is returning the complete animated gif as a blob. I think this may be my problem.
Any ideas on how to make this work?
Upvotes: 0
Views: 1248
Reputation: 1118
Thanks @tadman for pointing me in the right direction. The output format of blob is ambiguous and I assumed since I had multiple images, and all of the animation options, that it would output a gif.
I found a post somewhere that someone needed to output the blob as a specific format (png) and was able to adapt the same usage.
this works for me:
gif.to_blob { |attrs| attrs.format = 'gif' }
Upvotes: 1