What's the best (or at least good enough) algorithm for auto-positioning images in a CSS sprite?

I wrote a CSS CSS sprite autogenerator that renders selected images from an HTML page and converts them to CSS sprites, but right now it doesn't try to lay out them optimally, but just stacks them, which wastes space a lot. What would be the best algorithm for determining the optimal layout?

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

0


source to share


1 answer


It was already here: Stacking rectangles takes up as little space as possible .



Perhaps this is what you are looking for.

+1


source







All Articles