PHPackages                             padam87/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. padam87/bin-packer

ActiveLibrary

padam87/bin-packer
==================

2D bin packing for PHP

v0.1.2(2y ago)239.1k↓100%7[2 PRs](https://github.com/Padam87/bin-packer/pulls)MITPHPPHP ^7.2 || ^8.0

Since May 23Pushed 2y ago2 watchersCompare

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

READMEChangelog (3)Dependencies (1)Versions (6)Used By (0)

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

[](#bin-packer)

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

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 growth by passing `true` as the 3rd parameter to the bin's constructor.

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

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

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

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 ~782 days

Total

3

Last Release

986d ago

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

v0.1.1PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/776488?v=4)[Adam Prager](/maintainers/Padam87)[@Padam87](https://github.com/Padam87)

---

Top Contributors

[![Padam87](https://avatars.githubusercontent.com/u/776488?v=4)](https://github.com/Padam87 "Padam87 (13 commits)")

---

Tags

bin-packingprintsheet

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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