How does it work? You choose the layout direction and Packery lays out the items by dropping them into the first slot that fits. (Note that this means that the items may not be laid out in order.) You can specify a gap between items and exclude some elements from the layout. To take one concrete example from the Packery documentation, you can specify that you want to place the items into 80 pixel wide columns, starting from the right.
For this type of library, documentation with images and live examples is better than words. And Packery has really good documentation, including a detailed list of all available options.
Finally, we should mention that Packery is dual-licensed under the GPL for non-commerical use and a paid license for other purposes.