首页 > 解决方案 > 从 pdf 创建缩略图

问题描述

我必须从 pdf 创建缩略图(以 png 或 jpg 格式)。我找到了 Imagik 库,它需要 GhostScript。两者都安装在主机上,但代码不起作用。我在官方文档中找到了。我在另一个带有图像标题的 php 文件中进行了测试,但没有成功。我是否必须创建一个带有图像标题的其他 php 文件并测试该文件是否已经存在?

<?php
try {
    $bdd = new PDO('mysql:host=*db url*;dbname=teg;charset=utf8', *user*, *password*);
}
catch (Exception $e){
    die('Erreur : ' . $e->getMessage());
}

$reponse = $bdd->query('SELECT * FROM kiosque ORDER BY date_publication DESC');

while ($kiosque = $reponse->fetch())
{
    $im = new Imagick();
    $im->setResolution(400, 565);
    $im->readImage('/resources/kiosque/'. $kiosque['edition'] . '.pdf[0]');
    $im->writeImages('/resources/kiosque/' . $kiosque['edition'] . '.png', false);
?>

<div class="edition">
    <img src="/resources/kiosque/<?php echo $kiosque['edition'];?>.png"></img>
    <h2>Edition #<?php echo $kiosque['numero']; ?></h2>
    <h3 class="date"><?php echo $kiosque['date_publication'];?></h3> 
    <p><?php echo $kiosque['description'];?></p>
    <a class="button" href="lire.php?numero=<?php echo $kiosque['numero'];?>&amp;date=<?php echo $kiosque['date_publication'];?>&amp;edition=<?php echo $kiosque['edition'];?>">Lire cette édition</a>
</div>

<?php
}

$reponse->closeCursor();
?>

标签: phppdfimagick

解决方案


推荐阅读