PHP code example of padam87 / bin-packer

1. Go to this page and download the library: Download padam87/bin-packer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

padam87 / bin-packer example snippets


$bin = new Bin(1000, 1000);
$blocks = [
    new Block(100, 100),
    new Block(300, 100),
    new Block(175, 125),
    new Block(200, 75),
    new Block(200, 75),
];

$packer = new BinPacker();

$blocks = $packer->pack($bin, $blocks);

foreach ($blocks as $block) {
    if ($block->getNode() && $block->getNode()->isUsed()) {
        // packed
    }
}

new Block(100, 100, false);

new Block(100, 100, false, 'My id, can be anything.');

$bin = new Bin(1000, 1000, true);

$bin = new Bin(1000, 1000);
$blocks = [
    new Block(100, 100),
    new Block(300, 100),
    new Block(175, 125),
    new Block(200, 75),
    new Block(200, 75),
];

$packer = new BinPacker();

$blocks = $packer->pack($bin, $blocks);

$image = $visualizer->visualize($bin, $blocks);

$image->setFormat('jpg');
$image->writeImage('bin.jpg');

$packer = new BinPacker();
$gifMaker = new GifMaker(new Visualizer());

$blocks = $packer->pack($bin, $blocks, $gifMaker);

$gif = $gifMaker->create();

$gif->writeImages('bin.gif', true);