将图像放入 pdf 区域,数学问题

发布于 2024-10-18 07:58:12 字数 189 浏览 7 评论 0原文

现在已经很晚了,我的大脑无法正常工作...

我有一个 244x175 像素的图像,我想缩放它以适合我使用 www.tcpdf.org。

我必须将其缩放多少才能正确适应?

提前致谢

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 技术交流群。

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

发布评论

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

评论(2

爱情眠于流年 2024-10-25 07:58:13

好的。 PDF 使用点。 1 磅是 1/72 英寸。 125 毫米 = 4.921 英寸。 4.921 * 72 = 354.312 点。小数点就好了。

看起来 TCPDF 抽象了大部分工作,除非您进行一些认真的挖掘,而您不需要这样做。

根据 Image 的文档,您所需要做的就是指定您的尺寸想要适应,它会按比例缩放另一个:

// draw an image that is 125mm wide, and scaled to whatever height is needed
// to maintain the same proportions
TCPDF::image($path, $xloc, $yloc, 
             354.321, 0, ''/*no link*/,
             ''/*use path extension for type*/,
             true /*resize*/ ); // and let the rest default

我自己从未使用过 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:

// draw an image that is 125mm wide, and scaled to whatever height is needed
// to maintain the same proportions
TCPDF::image($path, $xloc, $yloc, 
             354.321, 0, ''/*no link*/,
             ''/*use path extension for type*/,
             true /*resize*/ ); // and let the rest default

I've never used TCPDF (or PHP for that matter) myself, but according to the docs, some variation on that will work.

猫烠⑼条掵仅有一顆心 2024-10-25 07:58:13

像素和毫米不是相同的单位。 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)

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