Is it possible to render blob images in a prawn document?

依然范特西╮ 提交于 2021-02-07 03:37:40

问题


I´m willing to use Gruff to render some graphics inside prawn documents.

I want to avoid the delay of writing images to the disk only for them to be read by Prawn.

Gruff offers the to_blob method that renders the graph image as a blob in memory, but looking at the prawn manual image section, it only gives us a way to render images directly from files.

Am I missing something? Is there a way to render it from memory?


回答1:


You should be able pass the image data as a StringIO

require 'stringio'
require 'pdf'

Prawn::Example.generate("foo.pdf") do |pdf|
  data = StringIO.new(render_my_image_to_a_string)
  pdf.image(data)
end 


来源:https://stackoverflow.com/questions/13769539/is-it-possible-to-render-blob-images-in-a-prawn-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!