dongshuo1257 2016-07-07 09:15
浏览 91
已采纳

imagemagick没有错误,但显示失败[?]“图像”

i'm new here but i've already found help for different problems!

i want to generate a jpeg-thumbnail from an online-generated pdf, but the pdf is generated from a php script... so i've to link to a .php script and not to a .pdf file. is that possible?

but my problem first is, when i simply link to a normal .pdf file i get no error, but also no picture. in safari there's only a icon like this: failure image

and firefox shows something like "the image has an error" but that's a text from the browser.

my code:

<?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)."' />"

?>

Thanx a lot for your help!

  • 写回答

1条回答 默认 最新

  • doumi6685 2016-07-07 12:15
    关注

    So i have the solution, maybe this would help somebody:

    $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'/>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于#flink#的问题:关于docker部署flink集成hadoop的yarn,请教个问题flink启动yarn-session.sh连不上hadoop
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题