陪伴而非守候
您可以在创建 pdf 之前压缩图像,如下所示:compressedImage($source, $path, $quality); //before create pdf// Compress image functionfunction 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.
繁星点点滴滴
您可以实现两种方式:您可以先通过这种类型的库减小图像大小,然后生成 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() )请参阅此处的文档