Php imagemagick无错误,但显示失败[?]”;“图像”;
我是新来的,但我已经找到了解决不同问题的方法 我想从在线生成的pdf生成jpeg缩略图,但pdf是从php脚本生成的。。。所以我必须链接到一个.php脚本,而不是一个.pdf文件。可能吗 但我的第一个问题是,当我简单地链接到一个普通的.pdf文件时,我没有得到任何错误,也没有得到任何图片。在safari中,只有这样一个图标: firefox显示类似“图像有错误”的内容,但这是来自浏览器的文本 我的代码:Php imagemagick无错误,但显示失败[?]”;“图像”;,php,pdf,imagemagick,jpeg,Php,Pdf,Imagemagick,Jpeg,我是新来的,但我已经找到了解决不同问题的方法 我想从在线生成的pdf生成jpeg缩略图,但pdf是从php脚本生成的。。。所以我必须链接到一个.php脚本,而不是一个.pdf文件。可能吗 但我的第一个问题是,当我简单地链接到一个普通的.pdf文件时,我没有得到任何错误,也没有得到任何图片。在safari中,只有这样一个图标: firefox显示类似“图像有错误”的内容,但这是来自浏览器的文本 我的代码: <?php $file = 'templates/pdf/standard/test
<?php
$file = 'templates/pdf/standard/test_doc.pdf';
$im = new imagick(realpath($file).'[0]');
$im->setImageFormat("jpg");
$im->resizeImage(200,200,1,0);
header("Content-Type: image/jpeg");
// start buffering
ob_start();
$thumbnail = $im->getImageBlob();
$contents = ob_get_contents();
ob_end_clean();
echo "<img src='data:image/jpg;base64,".base64_encode($contents)."' />"
?>
谢谢你的帮助 所以我有了解决方案,也许这会对某人有所帮助:
$im = new Imagick();
$im->setResolution(200,200);
$im->readimage('templates/pdf/standard/file.pdf');
$im->setImageFormat('jpeg');
echo "<img src='data:image/jpeg;base64,".base64_encode($im->getImageBlob())."' width='524px' height='741px'/>";
$im=new Imagick();
$im->setResolution(200200);
$im->readimage('templates/pdf/standard/file.pdf');
$im->setImageFormat('jpeg');
回显“getImageBlob())。”'width='524px'height='741px'/>”;
所以我有了解决方案,也许这会对某人有所帮助:
$im = new Imagick();
$im->setResolution(200,200);
$im->readimage('templates/pdf/standard/file.pdf');
$im->setImageFormat('jpeg');
echo "<img src='data:image/jpeg;base64,".base64_encode($im->getImageBlob())."' width='524px' height='741px'/>";
$im=new Imagick();
$im->setResolution(200200);
$im->readimage('templates/pdf/standard/file.pdf');
$im->setImageFormat('jpeg');
回显“getImageBlob())。”'width='524px'height='741px'/>”;
首先尝试使用JPEG/PNG文件,因为需要安装ghostscript
来处理PDF。您可以使用URL作为ImageMagick的输入,只需确保它是可信的并了解风险,$file=”http://something/xxx.php“
。我得到的结果与:$file='templates/pdf/standard/06.jpg';好的,您的脚本没有在您认为的目录中运行。尝试让它输出其当前工作目录echo getcwd()。“\n”代码>,或尝试在路径开始处添加斜杠$file=“SLASHtemplates…”
我不明白你的意思。。。使用echo getcwd()。“\n”;我正在获取test.php脚本的路径。这是正确的!?如果您将/scripts
作为工作目录,那么当您将模板/pdf/standard
附加到该目录上时,您将在/scripts/templates/pdf/standard
中查找pdf,我怀疑您的pdf是否在/scripts
目录下。请先尝试使用JPEG/PNG文件,因为您需要安装ghostscript
来处理pdf。您可以使用URL作为ImageMagick的输入,只需确保它是可信的并了解风险,$file=”http://something/xxx.php“
。我得到的结果与:$file='templates/pdf/standard/06.jpg';好的,您的脚本没有在您认为的目录中运行。尝试让它输出其当前工作目录echo getcwd()。“\n”代码>,或尝试在路径开始处添加斜杠$file=“SLASHtemplates…”
我不明白你的意思。。。使用echo getcwd()。“\n”;我正在获取test.php脚本的路径。这是正确的!?如果您将/scripts
作为您的工作目录,那么当您将模板/pdf/standard
附加到该目录上时,您将在/scripts/templates/pdf/standard
中查找您的pdf,我怀疑您的pdf是否在/scripts
目录下。