Search code examples
algorithmpackingbin-packing

Fitting rectangles together in optimal fashion


I was wondering if anyone knows of any algorithms suited to fitting together N number of rectangles of unknown size into the smallest possible containing rectangle.

By optimal I mean with reducing the amount of white space left over in the resulting containing rectangle.

I would like to use this to generate css sprites from a series of images.

Many Thanks,

Ian


Solution

  • Through packing images into square texture and Simon's answer I got to this link http://code.activestate.com/recipes/442299/

    I did not check the recipe, but it seems to allow using non-square containers.