使用Prawn添加图像,出现错误:Prawn :: Errors :: UnsupportedImageType,PNG使用不受支持的交错方法(Add image using Prawn, got error: Prawn::Errors::UnsupportedImageType, PNG uses unsupported interlace method)
我使用Prawn来创建PDF文件,我想把文件放在文件中。 我已经看过这个网站创建pdf来引用如何添加图像。
这是我在
ExamResultPdf.rb
文件中生成pdf的代码:def initialize(exam, view) super(top_margin: 70) @exam = exam exam_number # line 9, I removed codes are not relevant end def exam_number logo_path = "#{Rails.root}/app/assets/images/logo_hoasen.png" image logo_path, height: 200, width: 200 text "Examination Result \##{@exam.id}", size: 30, style: :bold end
但是当我去页面
/result.pdf
,它有错误:Prawn::Errors::UnsupportedImageType in ExamsController#result PNG uses unsupported interlace method # Trace app/pdfs/exam_result_pdf.rb:18:in `exam_number' app/pdfs/exam_result_pdf.rb:9:in `initialize' app/controllers/exams_controller.rb:43:in `new' app/controllers/exams_controller.rb:43:in `block (2 levels) in result' app/controllers/exams_controller.rb:40:in `result'
我的
exams_controller
:def result @exam = Exam.find(params[:id]) @general_exam = GeneralExam.where(id: @exam.general_exam_id).first @topic_questions = TopicQuestion.where(general_exam_id: @general_exam.id) @exam_result = ExamResult.where(exam_id: @exam.id, user_id: @exam.user_id).first respond_to do |format| format.html format.pdf do pdf = ExamResultPdf.new(@exam, view_context) # line 43 send_data pdf.render, filename: "exam_result_#{@exam.id}", type: "application/pdf", disposition: "inline" end end end
所以我想问为什么我得到这个错误,Prawn不支持png文件? 我怎样才能把图像放在pdf文件中?
更新
我使用过
jpg
或jpeg
文件,但它也没有用。I used Prawn to create pdf file, I want to put the logo in file. I have looked at this site Creating pdf to reference how to add image.
This is my code in
ExamResultPdf.rb
file to generate pdf:def initialize(exam, view) super(top_margin: 70) @exam = exam exam_number # line 9, I removed codes are not relevant end def exam_number logo_path = "#{Rails.root}/app/assets/images/logo_hoasen.png" image logo_path, height: 200, width: 200 text "Examination Result \##{@exam.id}", size: 30, style: :bold end
But when I go to page
/result.pdf
, it has error:Prawn::Errors::UnsupportedImageType in ExamsController#result PNG uses unsupported interlace method # Trace app/pdfs/exam_result_pdf.rb:18:in `exam_number' app/pdfs/exam_result_pdf.rb:9:in `initialize' app/controllers/exams_controller.rb:43:in `new' app/controllers/exams_controller.rb:43:in `block (2 levels) in result' app/controllers/exams_controller.rb:40:in `result'
My
exams_controller
:def result @exam = Exam.find(params[:id]) @general_exam = GeneralExam.where(id: @exam.general_exam_id).first @topic_questions = TopicQuestion.where(general_exam_id: @general_exam.id) @exam_result = ExamResult.where(exam_id: @exam.id, user_id: @exam.user_id).first respond_to do |format| format.html format.pdf do pdf = ExamResultPdf.new(@exam, view_context) # line 43 send_data pdf.render, filename: "exam_result_#{@exam.id}", type: "application/pdf", disposition: "inline" end end end
So I want to ask why I got this error, Prawn is not support png file? How can I put image in pdf file?
Update
I have used
jpg
orjpeg
file, but it did not work too.
原文:https://stackoverflow.com/questions/13741110
最满意答案
JFreeSane在使用颜色空间时遇到了一个问题,它在0.97版本中得到修复:
https://github.com/sjamesr/jfreesane/releases/tag/jfreesane-0.97
There was an issue in JFreeSane with colorspaces, it was fixed in version 0.97:
https://github.com/sjamesr/jfreesane/releases/tag/jfreesane-0.97
相关问答
更多-
JFreeSane在使用颜色空间时遇到了一个问题,它在0.97版本中得到修复: https://github.com/sjamesr/jfreesane/releases/tag/jfreesane-0.97 There was an issue in JFreeSane with colorspaces, it was fixed in version 0.97: https://github.com/sjamesr/jfreesane/releases/tag/jfreesane-0.97
-
使用JQuery为背景颜色的饱和度或亮度设置动画(Animate background color's saturation or lightness using JQuery)[2022-03-28]
这个jsfiddle 1可能有帮助吗? 它会在悬停时随机更改background-color 。 更新:随着jsfiddle 2进行一些改动 (要使速度变慢,请在动画中提高整数值)。 This jsfiddle 1 maybe helps? It changes the background-color randomly on hover. Update: with a little changes you get following jsfiddle 2 (to make it slower, raise ... -
“ Legend字段仅接受column ,而不接受measures作为输入。 因此,如果将度量拖动到字段,则不会发生任何事情。 它只接受一个列的原因是因为它不符合您对图例的意义(即图表,图表,绘图,地图,表格等中使用的符号的简明解释) [1] ,它用于进一步切片/细分您感兴趣的数据(例如Premium类型/ LOB等)。 所以我的建议是你只需添加一个文本框来输入图例(即High: red, Medium: orange, Low: green ); 或者更好的是,您可以将具有不同颜色和描述的图像添加到报告中 ...
-
图像颜色饱和度(Image color saturation)[2022-08-25]
将RGB像素转换为HLS,通过sat输入缩放S,然后转换回RGB。 伪代码,假设所有颜色分量都在0.0到1.0的范围内: rgb_to_hls(r, g, b, h, l, s); s = s * sat hls_to_rgb(h, l, s, r, g, b); return r, g, b 如果你需要RGB / HLS转换功能, 这里就是 。 Convert the RGB pixel to HLS, scale the S by your sat input, then convert back t ... -
手写笔实际上具有内置功能。 根据文档色调 , 饱和度 : 以下应该有效: hue(#00c, 90deg) saturation(#00c, 50%) Stylus actually has built-in functions for these. Based off the docs hue, saturation: The following should work: hue(#00c, 90deg) saturation(#00c, 50%)
-
在支持CSS3的浏览器中,不需要将HSL颜色转换为RGB,因为您可以像这样分配它们: function rand(min, max) { return min + Math.random() * (max - min); } function get_random_color() { var h = rand(1, 360); var s = rand(0, 100); var l = rand(0, 100); return 'hsl(' + h + ',' + ...
-
这里有一些事情正在进行。 首先,HSB == HSV, 在这篇文章中讨论 。 接下来,HSB(V)色彩空间和HSL色彩空间是两个不同的野兽。 以下图像可以帮助将其可视化并显示您获得的值: 至于如何转换它们: A few things are going on here. First, HSB == HSV, as discussed in this post. Next, the HSB(V) color space and HSL color space are two different beasts. ...
-
http://www.graficaobscura.com/matrix/index.html上有一些详细信息,但您可能希望发布其他代码。 对每像素执行操作非常常见,并且通常不会遇到此类操作的性能问题。 .NET的Bitmap.SetPixel非常慢。 在codeproject上有一个很好的C#图像处理系列 ,显示了一个更快的方法。 我没有c ++ - cli的经验,但我会看看。 There are some details at http://www.graficaobscura.com/matrix/i ...
-
增加图像饱和度(Increase image saturation)[2023-09-25]
我认为最简单的方法肯定是转换为HSV色彩空间 ,根据需要增加饱和度值,然后将其转换回RGB图像 : hsvImage = rgb2hsv(rgbImage); %# Convert the image to HSV space hsvImage(:,:,2) = 1; %# Maximize the saturation rgbImage = hsv2rgb(hsvImage); %# Convert the image back to RGB space I think the ... -
我希望它们是基于RGB的值。 我做了一个搜索: http : //en.wikipedia.org/wiki/HSL_and_HSV HSL和HSV是RGB颜色模型中两个最常见的圆柱坐标表示。 例 @h: hue(#167e8a); @s: saturation(#167e8a); @l: lightness(#167e8a); .foo{ color: hsl(@h,@s,@l); } I would expect them to be RGB based values. I did a ...