title: PHP batch convert all images in a folder to jpg using Image Magick
body: <p>I have uploaded a number of images with different formats to a folder on my server. Using ImageMagick I want to convert them and replace them to JPG.</p>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;?php
  
  try
  {
          /*** the image file ***/
          $image = 'temp_images/*.*';
  
          /*** a new imagick object ***/
          $im = new Imagick();
  
          /*** ping the image ***/
          $im-&gt;pingImage($image);
  
          /*** read the image into the object ***/
          $im-&gt;readImage( $image );
  
          /**** convert to png ***/
          $im-&gt;setImageFormat( "jpg" );
  
          /*** write image to disk ***/
          $im-&gt;writeImage( 'temp_images/input/*.jpg' );
  
          echo 'Image Converted';
  }
  catch(Exception $e)
  {
          echo $e-&gt;getMessage();
  }
  
  ?&gt;
  </code></pre>
  
  <p>When I specify a particular image it converts it, when I replace say <code>abc.gif</code> to <code>*.*</code> I get the following error. </p>
  
  <blockquote>
    <p>'unable to open image <code>temp_images/input/*.*</code>: No such file or directory @ error/blob.c/OpenBlob/2638'</p>
  </blockquote>
  
  <p>In the documentation I read that I can use mogrify but I do not know who to insert comand line into PHP.</p>