title: Converting multipage pdf to multi images
body: <p>I am trying to convert a multipage PDF File to images by using PHP Image magic extension.The problem is that instead of getting images corresponding to each page of the file, I am getting the last page of pdf as the output image. Here is the code:</p>
  
  <pre><code>$handle = fopen($imagePath, "w");
  $img1 = new Imagick();
  
  $img1-&gt;setResolution(300,300);
  $img1-&gt;readImage(path to pdf file);
  $img1-&gt;setColorspace(imagick::IMGTYPE_GRAYSCALE);
  $img1-&gt;setCompression(Imagick::COMPRESSION_JPEG);
  $img1-&gt;setCompressionQuality(80);
  $img1-&gt;setImageFormat("jpg");
  
  $img1-&gt;writeImageFile($handle);
  </code></pre>
  
  <p>What am I doing wrong?The convert command on commandline with the same parameters works.</p>