如何提高 ReportLab 图像质量?

发布于 12-27 10:48 字数 401 浏览 4 评论 0原文

我正在建造一台标签打印机。它由一个标志和一些文字组成,并不难。我已经花了 3 天的时间尝试将原始 SVG 徽标绘制到屏幕上,但 SVG 太复杂,使用了太多渐变等。

所以我有一个高质量的位图徽标(JPG 或 PNG 格式),我将其绘制在 ReportLab 画布上。相关图像远大于 85*123px。我这样做是希望 ReportLab 能够嵌入整个内容并相应地对其进行扩展。我是这样做的:

canvas.drawImage('logo.jpg', 22+xoffset, 460, 85, 123)

问题是,我的假设是错误的。它似乎在屏幕分辨率下将其缩小到 85*123px,这意味着打印时看起来不太好。

ReportLab 是否有针对画布或文档的 DPI 命令,以便我可以保持质量正常?

I'm building a label printer. It consists of a logo and some text, not tough. I have already spent 3 days trying to get the original SVG logo to draw to screen but the SVG is too complex, using too many gradients, etc.

So I have a high quality bitmapped logo (as a JPG or PNG) and I'm drawing that on a ReportLab canvas. The image in question is much larger than 85*123px. I did this hoping ReportLab would embed the whole thing and scale it accordingly. Here's how I'm doing it:

canvas.drawImage('logo.jpg', 22+xoffset, 460, 85, 123)

The problem is, my assumption was incorrect. It seems to scale it down to 85*123px at screen resolution and that means when it's printed, it doesn't look great.

Does ReportLab have any DPI commands for canvases or documents so I can keep the quality sane?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

强者自强2025-01-03 10:48:07

我之前在 ReportLab 公司工作过,我可以告诉您,光栅图像在包含在 PDF 中时不会经过任何自动重采样/缩小尺寸。您使用的 85*123 尺寸不是像素,而是点 (pt),它是毫米或英寸等物理单位。

我建议使用不同质量的图像打印 PDF 以确认这一点,或者使用 PDF 查看器放大非常非常远。由于图像被重新采样两次(一次在成像软件中,然后再次对 PDF 查看器可用的像素),它在 PDF 查看器中看起来总是有点模糊。

这就是我如何计算制作光栅图像的像素大小,以便在给定的物理尺寸下很好地打印:

假设我希望图片为 2 英寸宽,每英寸有 72 个点,因此我的代码中的宽度将为 144。我知道打印的良好清晰分辨率是 300dpi(每英寸点数),因此光栅图像以 600 像素宽保存。

Having previously worked at the ReportLab company, I can tell you that raster images do not go through any automatic resampling/downscaling while being included in the PDF. The 85*123 dimensions you are using are not pixels, but points (pt) which are a physical unit like millimetres or inches.

I would suggest printing the PDF with different quality images to confirm this or otherwise zooming in very, very far using your PDF viewer. It will always look a bit fuzzy in a PDF viewer as the image is resampled twice (once in the imaging software and then again to the pixels available to the PDF viewer).

This is how I would calculate what size in pixels to make a raster image for it to print well at a given physical size:

Assume I want the picture to be 2 inches wide, there are 72 points in a inch so the width in my code would be 144. I know that a good crisp resolution to print at is 300dpi (dots per inch) so the raster image is saved at 600px wide.

债姬2025-01-03 10:48:07

我在写问题时想到的一个选择是:增加 PDF 的大小并让打印机整理内容。

如果我将所有数字乘以 5 并且打印机确实能够计算出结果,那么我的分辨率将接近 350DPI……但我只是做了一个假设。

One option that I thought of while writing the question is: increase the size of the PDF and let the printer sort things out.

If I just multiplied all my numbers by 5 and the printer did manage to figure things out, I'd have close to 350DPI... But I'm making quite an assumption.

破晓2025-01-03 10:48:07

我不知道它是否适用于所有人,但就我而言它确实有效。

我只需要在顶部添加一个徽标,因此我使用了drawImage()

但将徽标的大小缩小了三分之一,

c.drawImage(company_logo,225,750,width=(483/3),height=(122/3))

我之前必须知道真实的公司徽标大小,这样它就不会变形。

我希望它有帮助!

I don't know if it will work for all but in my case it did.

I only needed to add a logo on the top so I used drawImage()

but shrank the size of the logo by a third

c.drawImage(company_logo,225,750,width=(483/3),height=(122/3))

I had to previously know the real company logo size so it does not get distorted.

I hope it helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文