Skip to content

Add support for packing generic object with width/height attributes

Latest
Compare
Choose a tag to compare
@soimy soimy released this 26 May 10:25
· 62 commits to master since this release

See below for changes in usage

let MaxRectsPacker = require("maxrects-packer").MaxRectsPacker;
const options = {
    smart: true,
    pot: true,
    square: false,
    allowRotation: true
}; // Set packing options
let packer = new MaxRectsPacker(1024, 1024, 2, options); // width, height, padding, options

let input = [ // any object with width & height is OK since v2.1.0
    {width: 600, height: 20, name: "tree", foo: "bar"},
    {width: 600, height: 20, name: "flower"},
    {width: 2000, height: 2000, name: "oversized background", {frameWidth: 500, frameHeight: 500}},
    {width: 1000, height: 1000, name: "background", color: 0x000000ff},
    {width: 1000, height: 1000, name: "overlay"}
];

packer.addArray(input); // Start packing with input array
packer.bins.forEach(bin => {
    console.log(bin.rects);
});