title: I need an algorithm that can fit n rectangles of any size in a larger one minimizing its area
body: <p>I need an algorithm that would take <em>n</em> rectangles of any sizes, and calculate a rectangle big enough to fit them all, minimizing its area so the wasted area is minimum, and also returning the position of all the smaller rectangles within.  </p>
  
  <p>The specific task I need this to implement on is in a sprite sheet compiler that would take individual PNG files and make a large PNG with all the images in it, so individual frames can be <em>blitted</em>  from this surface at run time.  </p>
  
  <p>A nice to have feature would be that it aims to a specific given width/height ratio, but it's not mandatory.  </p>
  
  <p>I'd prefer simple, generic code I can port to another language.</p>