【发布时间】:2018-07-11 08:14:18
【问题描述】:
我正在使用 Sonata Media Bundle 和 Imagick,希望为 PDF 生成预览图像。 Ghostscript 已安装。我尝试以下方法:
$binaryContent = $media->getBinaryContent();
$tempPdfFile = tempnam(sys_get_temp_dir(),'pdf');
$tempJpegFile = tempnam(sys_get_temp_dir(),'jpeg');
file_put_contents($tempPdfFile, $binaryContent);
rename($tempPdfFile, $tempPdfFile . '.pdf');
rename($tempJpegFile,$tempJpegFile . '.jpg');
$im = new \Imagick($tempPdfFile . '.pdf');
$im->setImageColorspace(255);
$im->setResolution(72,72);
$im->setCompressionQuality(75);
$im->setImageFormat('jpeg');
$im->writeImage($tempJpegFile.'.jpg');
$im->clear();
$im->destroy();
...但我收到此错误消息:
读取文件失败
...上线$im = new \Imagick($tempPdfFile . '.pdf');
我在这里做错了什么?
====
附加信息:我也试过$im = new \Imagick($tempPdfFile . '.pdf[0]');,没有任何改善。
【问题讨论】: