是否支持Do​​mpdf max-height max-width?

时间:2015-01-22 15:12:59

标签: php css dompdf

我试图将图像限制为一定的高度和宽度。所以我很自然地使用max-height和max-width,这样当图像达到最大值时,图像可以保持纵横比。在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真的支持max-width和max-height吗?

1 个答案:

答案 0 :(得分:1)

使用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);
相关问题