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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘