title: resize multiple images in php without exceeding memory limit
body: <p>I am currently trying to get a form which will allow multiple images to be uploaded and resized on the server using PHP. Each uploaded image by the client is around 2.5mb in size.</p>
  
  <p>I am currently using the <code>move_uploaded_file()</code> function.</p>
  
  <p>There are no issues to move the files onto the server. The problem arises when I try to crop. Having not <strong>ImageMagick</strong> on my host I am using this setup (not all the code just what's relevant, this is in a loop with <code>$width</code> etc. changing for the different crop sizes)</p>
  
  <pre><code>$image_p = imagecreatetruecolor($width, $height);
  $image = imagecreatefromjpeg($filename);
  imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
  imagejpeg($image_p, $output_filename, 80);
  </code></pre>
  
  <p>As it stands this will only work for 2 images. If there is 3 or more submitted I get a 'memory exhausted' error. I have researched into this as my memory limit is 120mb. Apparently the <code>imagecreatefromjpeg</code> function uses a lot of memory, especially if the file has a large resolution (which mine does - hence why I need them cropped/resized).</p>
  
  <p>Does anyone know of a more efficient approach to this task? I have researched on google but everyone uses the same technique I am.</p>