{"id":21224082,"url":"https://github.com/kodie/php-img-items","last_synced_at":"2025-03-15T01:40:21.341Z","repository":{"id":57007982,"uuid":"400827009","full_name":"kodie/php-img-items","owner":"kodie","description":"Finds individual items inside an image and gets their size/coordinates.","archived":false,"fork":false,"pushed_at":"2023-01-06T19:51:11.000Z","size":1194,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T17:33:20.466Z","etag":null,"topics":["detect","extract","gdimage","image","image-processing","php","screenshot"],"latest_commit_sha":null,"homepage":"","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/kodie.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-28T15:30:44.000Z","updated_at":"2021-09-07T16:15:12.000Z","dependencies_parsed_at":"2023-02-06T08:15:47.823Z","dependency_job_id":null,"html_url":"https://github.com/kodie/php-img-items","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodie%2Fphp-img-items","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodie%2Fphp-img-items/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodie%2Fphp-img-items/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodie%2Fphp-img-items/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kodie","download_url":"https://codeload.github.com/kodie/php-img-items/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243672362,"owners_count":20328762,"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":["detect","extract","gdimage","image","image-processing","php","screenshot"],"created_at":"2024-11-20T22:54:57.021Z","updated_at":"2025-03-15T01:40:21.319Z","avatar_url":"https://github.com/kodie.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# img-items\n\n[![packagist package version](https://img.shields.io/packagist/v/kodie/img-items.svg?style=flat-square)](https://packagist.org/packages/kodie/img-items)\n[![packagist package downloads](https://img.shields.io/packagist/dt/kodie/img-items.svg?style=flat-square)](https://packagist.org/packages/kodie/img-items)\n[![license](https://img.shields.io/github/license/kodie/php-img-items.svg?style=flat-square)](license.md)\n\nFinds individual items inside an image and gets their size/coordinates. A PHP port of the [img-items](https://github.com/kodie/img-items) Node module.\n\n## Example\n\n| Source                       | Result                              |\n:-----------------------------:|:------------------------------------:\n| ![](assets/feed-example.png) | ![](assets/feed-example-filled.png) |\n\n```php\n\u003c?php\nrequire_once('vendor/autoload.php');\n\n$contents = file_get_contents('assets/feed-example.png');\n$img = imagecreatefromstring($contents);\n$items = img_items($img);\n\nforeach($items as $item) {\n  for ($y = $item['top']; $y \u003c $item['bottom'] + 1; $y++) {\n    for ($x = $item['left']; $x \u003c $item['right'] + 1; $x++) {\n      imagesetpixel($img, $x, $y, imagecolorallocate($img, 255, 0, 0));\n    }\n  }\n}\n\nimagepng($img, 'assets/feed-example-filled.png', 0);\nimagedestroy($img);\n?\u003e\n```\n\n## Caveat\n\nThe larger the image and/or the more background colors defined to compare against, the slower the module will run. There are more than likely some things that could be approved upon to make it more efficient but it does work as is.\n\n## Installation\n\n```shell\ncomposer require kodie/img-items\n```\n\n## Usage\n\n`img_items(image, options)`\n\n```php\n\u003c?php\nrequire_once('vendor/autoload.php');\n\n$items = img_items('my-image.jpg', array(\n  'background'           =\u003e 0,\n  'background_threshold' =\u003e 5,\n  'gap_threshold'        =\u003e 5,\n  'size_threshold'       =\u003e 5\n));\n?\u003e\n```\n\n### Parameters\n\n#### `$image`\n\nThe image to scan for items. Accepts a file path to an image, a [gd Image Resource](https://www.php.net/manual/en/image.resources.php), or a [GdImage Instance](https://www.php.net/manual/en/class.gdimage.php).\n\n#### `$options`\n\nAn array with options you can set to tweak how items are found:\n\n  * `background` (Default: `0`) - The color(s) that should be considered the background of the image. Accepts any string with a color value that the [color component factory](https://github.com/spatie/color#factoryfromstring-color) can convert to a color (examples: `#FFFFFF`, `rgb(255, 0, 0)`, `hsl(240, 100%, 50%)`), an array of those color strings, an integer set to `0` to use the top left pixel color, an integer set to `-1` to set the background color to either black or white depending on the average luminance of the image, or an integer from `1` to `10` to use that number of primary colors from the image. *(Keep in mind that the more colors that are defined here, the slower the module will run.)*\n\n  * `background_threshold` (Default: `5`) - An integer from `0` to `100` defining how close a color can be to the background color (using the [CIE76 Color Difference Formula](https://en.wikipedia.org/wiki/Color_difference#CIE76)) for it to be considered part of the background. `0` being an exact match.\n\n  * `gap_threshold` (Default: `5`) - An integer defining how many pixels of background color before an item is considered it's own item.\n\n  * `gap_y_threshold` (Default: `null`) - The same as `gap_threshold` but only on the `Y` axis. (Setting to `null` will fallback to `gap_threshold`)\n\n  * `gap_x_threshold` (Default: `null`) - The same as `gap_threshold` but only on the `X` axis. (Setting to `null` will fallback to `gap_threshold`)\n\n  * `size_threshold` (Default: `5`) - An integer defining how many pixels wide and high an item should be to make the cut. If an item has a width or height lower than this value it will be filtered out of the results.\n\n  * `height_threshold` (Default: `null`) - The same as `size_threshold` but only for the item's height. (Setting to `null` will fallback to `size_threshold`)\n\n  * `width_threshold` (Default: `null`) - The same as `size_threshold` but only for the item's width. (Setting to `null` will fallback to `size_threshold`)\n\n### Example Response\n\n```text\nArray\n(\n  [0] =\u003e Array\n    (\n      [left] =\u003e 728\n      [top] =\u003e 42\n      [right] =\u003e 782\n      [bottom] =\u003e 62\n      [width] =\u003e 55\n      [height] =\u003e 21\n    )\n  [1] =\u003e Array\n    (\n      [left] =\u003e 47\n      [top] =\u003e 44\n      [right] =\u003e 58\n      [bottom] =\u003e 61\n      [width] =\u003e 12\n      [height] =\u003e 18\n    )\n  [2] =\u003e Array\n    (\n      [left] =\u003e 66\n      [top] =\u003e 44\n      [right] =\u003e 93\n      [bottom] =\u003e 61\n      [width] =\u003e 28\n      [height] =\u003e 18\n    )\n)\n```\n\n## Related\n\n - [img-items](https://github.com/kodie/img-items) - The Node module this module was based on.\n\n## License\n\nMIT. See the [license.md file](license.md) for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkodie%2Fphp-img-items","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkodie%2Fphp-img-items","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkodie%2Fphp-img-items/lists"}