Tag: png

使用Base64中的图像生成带有图像的PDF

我想在一个pdf中保存多个png。 我从API调用收到的PNG到Endicia Label Server,它给我一个Base64编码图像作为响应。 基于这个问题: 如何在不保存Rails服务器的情况下使用Prawn将base64字符串转换为PNG def batch_order_labels @orders = Spree::Order.ready_to_ship.limit(1) dt = Date.current.strftime(“%d %b %Y “) title = “Labels – #{dt} – #{@orders.count} Orders” Prawn::Document.generate(“#{title}.pdf”) do |pdf| @orders.each do |order| label = order.generate_label if order.international? @image = label.response_body.scan(/([^]*)/imu).flatten.last else @image = label.image end file = Tempfile.new(‘labelimg’, :encoding => ‘utf-8’) file.write Base64.decode64(@image) file.close pdf.image file […]

Ruby,RSVG和PNG流

我正在尝试在从SVG到PNG的rails应用程序中进行图像转换。 由于Heroku此时无法/想要升级IM,因此ImageMagick无法为我工作。 我正在测试一些在开发中使用RSVG2 / Cairo但遇到障碍的想法。 我可以轻松地将SVG转换并保存为PNG,如下所示: #svg_test.rb require ‘debugger’ require ‘rubygems’ require ‘rsvg2’ SRC = ‘test.svg’ DST = ‘test.png’ svg = RSVG::Handle.new_from_file(SRC) surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, 800, 800) context = Cairo::Context.new(surface) context.render_rsvg_handle(svg) surface.write_to_png(DST) 但这只能让我写出PNG文件。 在应用程序中,我需要能够动态生成这些内容,然后将它们作为数据发送到客户端浏览器。 我无法弄清楚如何做到这一点,或者即使它得到支持。 我知道我至少可以调用surface.data来获取原始数据,但我对图像格式知之甚少,不知道如何将其作为PNG。 谢谢

在Rails中渲染PNG文件

我有一个Rails应用程序,我试图显示一个PNG文件,但我收到此错误: ActionView::Template::Error (Your template was not saved as valid UTF-8. Please either specify UTF-8 as the encoding for your template in your text editor, or mark the template with its encoding by inserting the following as the first line of the template: # encoding: . The source of your template was: PNG IHDR#ͱ ) pHYs […]

Ruby中的Base64 jpg到base64 Png

我正在使用base64文件,我想在base64png图像中转换base64jpg图像。 有办法吗? 原因是我使用rsvg-convert将svg文件转换为png文件,但是当我在svg中有base64jpg时,它不起作用,但它适用于base64文件。