支持与否的 dompdf 最大高度最大宽度


Dompdf max-height max-width supported or not?

我试图将图像限制为最大高度和宽度。因此,我自然而然地使用最大高度和最大宽度,以便图像在达到最大值时可以保持其纵横比。在html中工作,这是我的代码片段

'<table class="seperate" id="images-table">'.   
        '<tbody>'.
          '<tr>'.
            '<td>&nbsp;</td>'.
            '<td class="uscs-logo" ><img src="http://localhost/dompdfTest/dompdf/uscompliancesystems_logo.png" /></td>'.
            '<td class="signature-logo" ><img src="http://localhost/dompdfTest/dompdf/USCSDefaultSignature.jpg" /></td>'.
            '<td>&nbsp;</td>'.
          '</tr>'.
        '</tbody>'.
    '</table>'.

和 css:

table#images-table .uscs-logo {
  height: 100px;
  text-align: left;
}
table#images-table .uscs-logo img{
    max-height:200px;
    max-width: 200px;
}
table#images-table .signature {
  height: 125px;
  text-align: right;
  width: 300px;
  height: auto;
  max-height:200px;
  max-width: 200px;
}

但是我在 pdf 中得到的是一个两页的 pdf,页面上没有图像,因为它们是全尺寸的。如果我以 html 格式呈现到页面,效果很好。

所以我的问题是,img 标签上的 dompdf 真的支持最大宽度和最大高度吗?

使用 GD PHP 扩展即时调整图像大小并不难。 就时间成本而言,如果您不这样做,浏览器必须扩展。

$filename ='/home/user/public_html/images/image.jpg';
$image = @imagecreatefromjpeg();
$originalWidth  = imagesx($image);
$originalHeight = imagesy($image);
$scale      = min($desiredWidth/$originalWidth, $desiredHeight/$originalHeight);
$newWidth  = ceil($scale*$originalWidth);
$newHeight = ceil($scale*$originalHeight);
$newPic = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($newPic, $image,0, 0, 0, 0,$newWidth, $newHeight, $originalWidth, $originalHeight);
if (imagejpeg($newPic,$tmpfile)){rename($tmpfile,$filename);}

并恢复内存清理。

imagedestroy($image);
imagedestroy($newPic);