I have a collection of different sized squares and rectangles that I want to fit together using PHP into one large square/rectangle. The squares are usually images that I want to make into a montage - but sometimes they are simply math objects.
Are there any PHP algorithms for this and what is this type of thing called?
Update: After more searching I think what I want is called the bin packing problem. However, I would also like to add a certain amount of randomization for certain types of packing problems (like images) to allow human interest.
2D Bin packing is NP-hard problem. There are however approximation algorithms.
Look at this code (and explanation). It contains multiple algorithms and there is a GUI:
Solving the 2D Packing Problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With