views:

91

answers:

1

I have written a CSS sprite auto-generator which takes selected images out of the HTML page and converts them to CSS sprites, but right now it does not attempt to lay them out optimally but rather just stacks them, which wastes a lot of space. What would be the best algorithm for determining the optimal layout?

To state the problem more generally, I need an algorithm that, given any number of rectangles of arbitrary size, will arrange them into a rectangle with the smallest possible area.

+1  A: 

This has been here already: Stacking rectangles to take as little space as possible.

Maybe that's what you're looking for.

Tomalak