{"id":21431573,"url":"https://github.com/padam87/bin-packer","last_synced_at":"2025-07-14T12:32:06.023Z","repository":{"id":34901061,"uuid":"188311943","full_name":"Padam87/bin-packer","owner":"Padam87","description":"2D bin packing for PHP, with rotation and growth function","archived":false,"fork":false,"pushed_at":"2024-05-18T00:41:17.000Z","size":3009,"stargazers_count":21,"open_issues_count":2,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-02T08:51:47.585Z","etag":null,"topics":["bin-packing","print","sheet"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Padam87.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-23T21:54:47.000Z","updated_at":"2024-09-18T02:24:58.000Z","dependencies_parsed_at":"2024-05-18T01:43:29.676Z","dependency_job_id":null,"html_url":"https://github.com/Padam87/bin-packer","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"274e95a56005007cf9af014d9ed9da9eaa265e8b"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Padam87%2Fbin-packer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Padam87%2Fbin-packer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Padam87%2Fbin-packer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Padam87%2Fbin-packer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Padam87","download_url":"https://codeload.github.com/Padam87/bin-packer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225976207,"owners_count":17554196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bin-packing","print","sheet"],"created_at":"2024-11-22T23:08:05.015Z","updated_at":"2024-11-22T23:08:05.529Z","avatar_url":"https://github.com/Padam87.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bin-packer\n2D bin packing for PHP, with rotation and growth function\n\n## Usage\n### Basic\n\n```php\n$bin = new Bin(1000, 1000);\n$blocks = [\n    new Block(100, 100),\n    new Block(300, 100),\n    new Block(175, 125),\n    new Block(200, 75),\n    new Block(200, 75),\n];\n\n$packer = new BinPacker();\n\n$blocks = $packer-\u003epack($bin, $blocks);\n```\n\n#### Determining the result (was a block packed?)\n\n```php\nforeach ($blocks as $block) {\n    if ($block-\u003egetNode() \u0026\u0026 $block-\u003egetNode()-\u003eisUsed()) {\n        // packed\n    }\n}\n```\n\n### Rotation\n\nBy default, all blocks are allowed to rotate. Rotation occures only if a fit is not found with the initial orientation.\n\nYou can disable rotation by passing `false` as the 3rd parameter to the block's constructor.\n```php\nnew Block(100, 100, false);\n```\n\n### Identifying blocks\n\nSometimes it can be useful to set an identifier for the block. The optional 4th parameter of the constructor is the block ID.\n\n```php\nnew Block(100, 100, false, 'My id, can be anything.');\n```\n\n### Bin growth\n\nBy allowing the bin to grow, you can fit all blocks, every time.\n\nYou can enable growth by passing `true` as the 3rd parameter to the bin's constructor.\n```php\n$bin = new Bin(1000, 1000, true);\n```\n\n## Visualizer\n\nYou can use the visualizer to create pictures of the packed bin.\n\n```php\n$bin = new Bin(1000, 1000);\n$blocks = [\n    new Block(100, 100),\n    new Block(300, 100),\n    new Block(175, 125),\n    new Block(200, 75),\n    new Block(200, 75),\n];\n\n$packer = new BinPacker();\n\n$blocks = $packer-\u003epack($bin, $blocks);\n\n$image = $visualizer-\u003evisualize($bin, $blocks);\n```\n\nThis feature uses the Imagick extension, and returns an \\Imagick class. You can use the result to save, or display the image.\n\n```php\n$image-\u003esetFormat('jpg');\n$image-\u003ewriteImage('bin.jpg');\n```\n\n![visualizer](docs/bin.jpg)\n\n## GIF creator\n\n**WARNING**\nThe GIF creators performance is very slow. I would suggest only using it for debug purposes, or non real-time scenarios\n\n```php\n$packer = new BinPacker();\n$gifMaker = new GifMaker(new Visualizer());\n\n$blocks = $packer-\u003epack($bin, $blocks, $gifMaker);\n\n$gif = $gifMaker-\u003ecreate();\n\n$gif-\u003ewriteImages('bin.gif', true);\n```\n\n![visualizer](docs/bin.gif)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadam87%2Fbin-packer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpadam87%2Fbin-packer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadam87%2Fbin-packer/lists"}