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

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

报告相同问题?