title: set density parameter for imagick with php
body: <p>I want to convert a pdf page to a png image with Imagick. </p>
  
  <p>I tried with PHP, but the image quality was very low.<br>When I tried with command line, the result was perfect.</p>
  
  <p><strong>PHP code</strong></p>
  
  <pre><code>$im = new imagick( __DIR__ . DIRECTORY_SEPARATOR.$PDFName.'['.$i.']' );  
  $params = $im-&gt;identifyImage();
  $width = $params['geometry']['width']*1;
  $height = $params['geometry']['height']*1;
  $im-&gt;setResolution(400,400);
  $im-&gt;resizeImage($width ,$height, imagick::FILTER_SINC, 1, true);
  $im-&gt;writeImage(__DIR__ . DIRECTORY_SEPARATOR.'pdf_pages\\'.$i.'.png'); 
  $im-&gt;clear(); 
  $im-&gt;destroy();
  </code></pre>
  
  <p><strong>Command line code</strong></p>
  
  <pre><code>convert -density 400 a.pdf -resize 25% -a.png
  </code></pre>
  
  <p><strong>PHP code (2nd attempt)</strong> </p>
  
  <pre><code>$im = new imagick( __DIR__ . DIRECTORY_SEPARATOR.$PDFName.'['.$i.']' );  
  $im-&gt;setOption('density','400x400');
  $im-&gt;setOption('resize','25%');
  $im-&gt;writeImage(__DIR__ . DIRECTORY_SEPARATOR.'pdf_pages\\'.$i.'.png'); 
  $im-&gt;clear(); 
  $im-&gt;destroy();
  </code></pre>
  
  <p>Still bad results.</p>
  
  <p>What can I do? I want to use the density parameter in my PHP code, but how?</p>
  
  <p><strong>Output with PHP</strong>
  <img src="https://i.stack.imgur.com/Mrj1M.png" alt="enter image description here"></p>
  
  <p><strong>Output with command line</strong>
  <img src="https://i.stack.imgur.com/hebVk.png" alt="enter image description here"></p>