我在插入 TCPDF 图像时遇到问题。

这是我正在使用的代码:
$this->Image($this->data['logo'], PDF_MARGIN_LEFT, 5, 60, 20, '', '', 'M', true);
Run Code Online (Sandbox Code Playgroud)
我已将调整大小设置为 true,但 TCPDF 库不考虑图像比例。
如何强制保留图像比例?
有关信息,我正在使用 TCPDF 6.2.8 (2015-04-29)。
感谢您的支持,大卫。
这是我找到的解决方案:
if ('' != $this->data['logo'] && is_file($this->data['logo'])) {
// select only one constraint : height or width. 60x20 image emplacement => ratio = 3 (60/20)
list($image_w, $image_h) = getimagesize($this->data['logo']);
if (3 > $image_w / $image_h) list($w, $h) = array(0, 20);
else list($w, $h) = array(60, 0);
$this->Image($this->data['logo'], PDF_MARGIN_LEFT, 5, $w, $h, '', '', 'M');
}
Run Code Online (Sandbox Code Playgroud)
我找到了图像放置比率(60/20=3),将其与图像比率进行比较,然后在设置宽度或高度之间进行选择。
感谢 JamesG 帮助我找到解决方案。
大卫。