1

There are images (literally, PNG files), they come in different sizes and need to be put together into a larger image, so that (1) they don’t overlap, and (2) the amount of unused pixels is minimal.

Can someone point me in the right direction? I can imagine that packing rectangles is nothing new, but honestly, I cannot find neither an implementation nor an algorithm for this.

ayanami
  • 1,588
  • 13
  • 20
  • 1
    When I google for **rectangle packing algorithm**, I get quite a few results, including [Wikipedia](http://en.wikipedia.org/wiki/Bin_packing_problem). – odrm Oct 30 '11 at 10:41
  • Searching for 'rectangle packing' gives http://stackoverflow.com/questions/125620/piece-together-several-images-into-one-big-image and http://www.blackpawn.com/texts/lightmaps/default.html (and http://stackoverflow.com/questions/153123/packing-rectangles-for-compact-representation) – kennytm Oct 30 '11 at 10:42

1 Answers1

2

This is one algorithm: Fast optimizing rectangle packing algorithm for building CSS sprites. The article includes an explanation and C# code. It also links to a paper that might be interesting.

Daan
  • 1,516
  • 12
  • 20