PHPackages                             6px/bin-packer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. 6px/bin-packer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

6px/bin-packer
==============

2D bin packing for PHP

v0.2.0(3y ago)1116[1 issues](https://github.com/6px/bin-packer/issues)MITPHPPHP ^7.2|^8.1CI failing

Since Dec 17Pushed 3y ago1 watchersCompare

[ Source](https://github.com/6px/bin-packer)[ Packagist](https://packagist.org/packages/6px/bin-packer)[ RSS](/packages/6px-bin-packer/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

bin-packer
==========

[](#bin-packer)

2D bin packing for PHP, with rotation and growth function

Forked from [Padam87/bin-packer](https://github.com/Padam87/bin-packer)

Usage
-----

[](#usage)

### Basic

[](#basic)

```
$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);
```

#### Determining the result (was a block packed?)

[](#determining-the-result-was-a-block-packed)

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

### Rotation

[](#rotation)

By default, all blocks are allowed to rotate. Rotation occures only if a fit is not found with the initial orientation.

You can disable rotation by passing `false` as the 3rd parameter to the block's constructor.

```
new Block(100, 100, false);
```

### Identifying blocks

[](#identifying-blocks)

Sometimes it can be useful to set an identifier for the block. The optional 4th parameter of the constructor is the block ID.

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

### Bin growth

[](#bin-growth)

By allowing the bin to grow, you can fit all blocks, every time.

You can enable width growth by passing `true` as the 3rd parameter to the bin's constructor and height growth by passing the fourth parameter

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

This bin will only be allowed to grow on it's width.

Visualizer
----------

[](#visualizer)

You can use the visualizer to create pictures of the packed bin.

```
$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);
```

This feature uses the Imagick extension, and returns an \\Imagick class. You can use the result to save, or display the image.

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

[![visualizer](docs/bin.jpg)](docs/bin.jpg)

GIF creator
-----------

[](#gif-creator)

**WARNING**The GIF creators performance is very slow. I would suggest only using it for debug purposes, or non real-time scenarios

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

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

$gif = $gifMaker->create();

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

[![visualizer](docs/bin.gif)](docs/bin.gif)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~398 days

Total

4

Last Release

1149d ago

PHP version history (2 changes)v0.1.1PHP ^7.2

v0.2.0PHP ^7.2|^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a214dd3e770b8f6e835a86d87e0da2321ef2cdddc15fdcd4fb98327562587a3?d=identicon)[jfoucher](/maintainers/jfoucher)

---

Top Contributors

[![jfoucher](https://avatars.githubusercontent.com/u/152015?v=4)](https://github.com/jfoucher "jfoucher (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/6px-bin-packer/health.svg)

```
[![Health](https://phpackages.com/badges/6px-bin-packer/health.svg)](https://phpackages.com/packages/6px-bin-packer)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
