title: Resizing lots of images via PHP, keeping aspect and not using all my RAM?
body: <p>I have a problem that I thought was easily solved, but is turning out a little more difficult than anticipated.</p>
  
  <p>I am working on a site which someone can upload images for a product, and it resizes them twice (500x500 and 150x150) on the fly. I am trying to keep the aspect ratio, for example if I had 600x500 image it would resize to 500x417 and 150x125.</p>
  
  <p>I have found (lots) of code that does this, such as <a href="http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/" rel="nofollow">this class</a>, however I always run into memory issues. I think  the class isn't unloading/destroying the temporary images after resizing.</p>
  
  <p>I had the host upgrade my memory-limit to 64M from 32, however I run out of memory later. I'm stuck with PHP 5.2.13 as well, so no garbage collector for me.</p>
  
  <p>My PHP is fairly new, so it's very alien to me how classes work, otherwise I would try adding the imagedestroy() function where required. I fiddled with the linked class for hours without success.</p>
  
  <p>Can anyone either:</p>
  
  <p>-Point me in the direction of a magic class that keeps aspect as well as unloading/destroying temporary images after resizing is complete, to keep RAM usage under control?</p>
  
  <p>-Give me some (much needed!) guidance on where and how I could modify a class (such as the one posted) to destroy temporary images.</p>
  
  <p>-Tell me if I'm going around this extremely wrong?</p>
  
  <p>Oh, and I had the WideImage class working at one point, and it worked great, then suddenly stopped. I spent hours trying to fix it with no success.</p>
  
  <p>My PHP install has GD, but not ImageMagick.</p>
  
  <p>Thanks!</p>