{"id":15284066,"url":"https://github.com/meyfa/phpunit-assert-gd","last_synced_at":"2026-03-02T15:47:23.403Z","repository":{"id":28962395,"uuid":"119818529","full_name":"meyfa/phpunit-assert-gd","owner":"meyfa","description":"PHPUnit matcher/assertions for GD image resources","archived":false,"fork":false,"pushed_at":"2025-07-27T08:31:32.000Z","size":95,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-08-27T19:15:21.152Z","etag":null,"topics":["assertions","comparison","gd","images","phpunit","similarity"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/meyfa/phpunit-assert-gd","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/meyfa.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},"funding":{"github":"meyfa"}},"created_at":"2018-02-01T10:10:52.000Z","updated_at":"2025-07-27T08:28:55.000Z","dependencies_parsed_at":"2024-04-16T12:36:26.705Z","dependency_job_id":"2b9ec2ae-ef53-4997-88af-d5ec1914395d","html_url":"https://github.com/meyfa/phpunit-assert-gd","commit_stats":{"total_commits":18,"total_committers":4,"mean_commits":4.5,"dds":"0.16666666666666663","last_synced_commit":"891a480e5305e2aae53f4e6526e723f7477c269c"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/meyfa/phpunit-assert-gd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meyfa%2Fphpunit-assert-gd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meyfa%2Fphpunit-assert-gd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meyfa%2Fphpunit-assert-gd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meyfa%2Fphpunit-assert-gd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meyfa","download_url":"https://codeload.github.com/meyfa/phpunit-assert-gd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meyfa%2Fphpunit-assert-gd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30008463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-02T15:15:59.058Z","status":"ssl_error","status_checked_at":"2026-03-02T15:15:58.758Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["assertions","comparison","gd","images","phpunit","similarity"],"created_at":"2024-09-30T14:48:56.696Z","updated_at":"2026-03-02T15:47:23.395Z","avatar_url":"https://github.com/meyfa.png","language":"PHP","funding_links":["https://github.com/sponsors/meyfa"],"categories":[],"sub_categories":[],"readme":"# AssertGD for PHPUnit\n\n[![CI](https://github.com/meyfa/phpunit-assert-gd/actions/workflows/main.yml/badge.svg)](https://github.com/meyfa/phpunit-assert-gd/actions/workflows/main.yml)\n\nTrying to assert images with PHPUnit? This project provides a constraint and the\nrequired assertions that allow you do to so.\n\nIt supports comparing **files on disk** as well as **image resources** in\nmemory.\n\n## Installation\n\nAdd this package to your Composer dev-dependencies:\n\n```\ncomposer require --dev meyfa/phpunit-assert-gd\n```\n\n**Compatibility table**\n\n| AssertGD version | Supported PHP version | Supported PHPUnit version |\n|:-----------------|:----------------------|:--------------------------|\n| 4.*              | \u003e= 8.1                | ^10.1 and ^11.0           |\n| 3.*              | \u003e= 7.3                | 9                         |\n| 2.*              | \u003e= 7.2                | 8                         |\n| 1.*              | 5.3.3 - 8.0           | 4.8.36 - 6.5.0            |\n\n## Examples\n\nThe assertions are available as a\n[trait](http://php.net/manual/en/language.oop5.traits.php), so you can easily\n`use` them in your test case class:\n\n```php\n\u003c?php\nuse AssertGD\\GDAssertTrait;\n\nclass ExampleTest extends PHPUnit\\Framework\\TestCase\n{\n    // this trait adds the assert methods to your test case\n    use GDAssertTrait;\n\n    public function testSomething()\n    {\n        $this-\u003eassertSimilarGD('./tests/expected.png', './tests/actual.png');\n    }\n}\n```\n\n### Plain comparisons\n\nUse `assertSimilarGD` if you expect 2 images to be exactly equal.\nUse `assertNotSimilarGD` if you expect there to be differences.\n\n```php\n$this-\u003eassertSimilarGD('./tests/img.png', './tests/same.png');\n$this-\u003eassertNotSimilarGD('./tests/img.png', './tests/other.png');\n```\n\n### Threshold values\n\nProvide a number between 0 and 1 to set the error threshold. For example, a\nvalue of 0.2 would allow for at most 20% difference.\n\n```php\n$this-\u003eassertSimilarGD('./tests/img.png', './tests/similar.png', '', 0.2);\n```\n\n### Parameter types\n\nInstead of file paths, you can pass in GD image resources. This eliminates\nhaving to write something to disk prior to the comparison.\n\n```php\n$img = imagecreatetruecolor(10, 10);\n$this-\u003eassertSimilarGD('./tests/empty-10x10.png', $img);\nimagedestroy($img);\n```\n\n### Manual constraint\n\nIf you need to configure mock objects or do other, more complex matching calls,\nuse `isSimilarGD` to obtain a constraint object (similar to what would be\nreturned by `equalTo`, `isTrue`, etc.).\n\n```php\n$this-\u003eassertThat(\n    './tests/actual.png',\n    $this-\u003eisSimilarGD('./tests/expected.png')\n);\n```\n\n## Difference calculation\n\nBy default, this library calculates the difference between two images by\ncomparing the RGBA color channel information at each pixel coordinate of the\nsource image and the test image, and averaging the difference between each\npixel to calculate the difference score.\n\nThis will work for the majority of cases, but may give incorrect scoring \nin certain circumstances, such as images that contain a lot of transparency.\n\nAn alternative calculation method, which scales the RGB color channels\nbased on their alpha transparency - meaning more transparent pixels will\naffect the difficulty score less to offset their less observable difference\non the image itself - can be enabled by adding a new `ScaledRgbChannels`\ninstance to the 5th parameter of the `assertSimilarGD` or `assertNotSimilarGD`\nmethods.\n\n```php\nuse AssertGD\\DiffCalculator\\ScaledRgbChannels;\n\npublic function testImage()\n{\n    $this-\u003eassertSimilarGD(\n        'expected.png',\n        'actual.png',\n        '',\n        0,\n        new ScaledRgbChannels()\n    );\n}\n```\n\n### Custom difference calculators\n\nIf you wish to completely customise how calculations are done in this\nlibrary, you may also create your own calculation algorithm by creating\na class that implements the `AssertGd\\DiffCalculator` interface.\n\nA class implementing this interface must provide a `calculate` method\nthat is provided two `GdImage` instances, and the X and Y co-ordinate\n(as `ints`) of the pixel being compared in both images.\n\nThe method should return a `float` between `0` and `1`, where 0 is\nan exact match and 1 is the complete opposite.\n\nYou may then provide an instance of the class as the 5th parameter of\nthe `assertSimilarGD` or `assertNotSimilarGD` method to use this\ncalculation method for determining the image difference.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeyfa%2Fphpunit-assert-gd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeyfa%2Fphpunit-assert-gd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeyfa%2Fphpunit-assert-gd/lists"}