2 回答
TA贡献1757条经验 获得超8个赞
您可以在创建 pdf 之前压缩图像,如下所示:
compressedImage($source, $path, $quality); //before create pdf
// Compress image function
function compressedImage($source, $path, $quality) {
$info = getimagesize($source);
if ($info['mime'] == 'image/jpeg'){
$image = imagecreatefromjpeg($source);
}elseif ($info['mime'] == 'image/gif'){
$image = imagecreatefromgif($source);
}elseif ($info['mime'] == 'image/png'){
$image = imagecreatefrompng($source);
}
imagejpeg($image, $path, $quality);
return $path;
}
或者使用来自 tcpdf 的类,比如
public
setJPEGQuality( $quality )
//------------------//
SetCompression( $compress = true )
Activates or deactivates page compression. When activated, the internal representation of each page is compressed, which leads to a compression ratio of about 2 for the resulting document. Compression is on by default. Note: the Zlib extension is required for this feature. If not present, compression will be turned off.
TA贡献1803条经验 获得超3个赞
您可以实现两种方式:
您可以先通过这种类型的库减小图像大小,然后生成 pdf 文件。或者,
您可以在通过 tcpdf 生成 pdf 时设置图像宽度和高度。如下所示:
Image( $file, $x = '', $y = '', $w = 0, $h = 0, $type = '', $link = '', $align = '', $resize = false, $dpi = 300, $palign = '', $ismask = false, $imgmask = false, $border = 0, $fitbox = false, $hidden = false, $fitonpage = false, $alt = false, $altimgs = array() )
请参阅此处的文档
- 2 回答
- 0 关注
- 179 浏览
添加回答
举报