将图像放入 pdf 区域,数学问题
It's late here and my brain doesn't work as it should so...
I have an image 244x175 pixels and I want to scale it in order to fit in an 125mm area for a PDF I am generating by using www.tcpdf.org.
How many much I have to scale it in order to fit correctly?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的。 PDF 使用点。 1 磅是 1/72 英寸。 125 毫米 = 4.921 英寸。 4.921 * 72 = 354.312 点。小数点就好了。
看起来 TCPDF 抽象了大部分工作,除非您进行一些认真的挖掘,而您不需要这样做。
根据 Image 的文档,您所需要做的就是指定您的尺寸想要适应,它会按比例缩放另一个:
我自己从未使用过 TCPDF(或 PHP),但根据文档,一些变化是可行的。
Okay. PDF uses points. 1 point is 1/72 of an inch. 125mm = 4.921 inches. 4.921 * 72 = 354.312 points. Fractional points are just fine.
And it looks like TCPDF abstracts much of the work away unless you do some serious digging, which you don't need to do.
According to the docs for Image, all you need to do is specify the dimension you want to fit, and it'll scale the other proportionally:
I've never used TCPDF (or PHP for that matter) myself, but according to the docs, some variation on that will work.
像素和毫米不是相同的单位。 PDF 文档不能以像素为单位工作,所以这并不重要。您只需将图像放置在正确的坐标处并指定以毫米为单位的宽度(您有 125 毫米,对吗?)
但是,如果您询问如何将其适应特定约束,如宽度 AND< /strong>高度是125毫米,这取决于你想要发生什么。可能的结果是:
图像放置在正确的高度,但宽度可能大于或小于高度限制。此时您想要发生的情况取决于您是否希望图像被裁剪或拉伸,甚至显示得比宽度限制更大。
如果宽度更大也没关系,您需要决定是否希望图像的宽度偏移图像本身的 X 坐标,以便图像居中,或者其他什么。
如果你希望它取决于宽度的约束,那么它是相同的:..
所以你有多种选择来决定你希望这个东西如何表现(如果我理解正确的话)
Pixels and mm are not the same units. PDF documents don't work in pixels so it doesn't matter. You just place the image at the right coordinates and specify a width in mm (which you have, 125mm, right?)
However, if you're asking how to fit it within a specific constraint, as where the width AND the height is 125mm, it kind of depends what you want to happen. Possible outcomes are:
the image is placed in a correct height but the width could be bigger or smaller than the height constraints. what you want to happen at that point depends on if you want the image to become cropped or stretched or even to be displayed bigger then the width constraints.
and if it's ok that it's bigger on the width, you need to decide if you want the width of the image to offset the X coordinates of the image itself so that the image becomes centered, or whatever.
and then it's the same for if you want it to depend on the constraints in the width:..
so you have multiple options on how you want this thing to behave (if I understand you correctly)