title: Create a thumbnail from a pdf
body: <p>I have to create a thumbnail (in png or jpg) from a pdf. I found the library Imagik and it need GhostScript. Both are intalled on the host but the code doesn't work. I found there in the official docs. I tested in an other php file with an image header but unsuccessfully. Does I have to create an other php file with an image header and test if the file already exist ?</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  try {
      $bdd = new PDO('mysql:host=*db url*;dbname=teg;charset=utf8', *user*, *password*);
  }
  catch (Exception $e){
      die('Erreur : ' . $e-&gt;getMessage());
  }
  
  $reponse = $bdd-&gt;query('SELECT * FROM kiosque ORDER BY date_publication DESC');
  
  while ($kiosque = $reponse-&gt;fetch())
  {
      $im = new Imagick();
      $im-&gt;setResolution(400, 565);
      $im-&gt;readImage('/resources/kiosque/'. $kiosque['edition'] . '.pdf[0]');
      $im-&gt;writeImages('/resources/kiosque/' . $kiosque['edition'] . '.png', false);
  ?&gt;
  
  &lt;div class=&quot;edition&quot;&gt;
      &lt;img src=&quot;/resources/kiosque/&lt;?php echo $kiosque['edition'];?&gt;.png&quot;&gt;&lt;/img&gt;
      &lt;h2&gt;Edition #&lt;?php echo $kiosque['numero']; ?&gt;&lt;/h2&gt;
      &lt;h3 class=&quot;date&quot;&gt;&lt;?php echo $kiosque['date_publication'];?&gt;&lt;/h3&gt; 
      &lt;p&gt;&lt;?php echo $kiosque['description'];?&gt;&lt;/p&gt;
      &lt;a class=&quot;button&quot; href=&quot;lire.php?numero=&lt;?php echo $kiosque['numero'];?&gt;&amp;amp;date=&lt;?php echo $kiosque['date_publication'];?&gt;&amp;amp;edition=&lt;?php echo $kiosque['edition'];?&gt;&quot;&gt;Lire cette édition&lt;/a&gt;
  &lt;/div&gt;
  
  &lt;?php
  }
  
  $reponse-&gt;closeCursor();
  ?&gt;
  </code></pre>