{"id":19325086,"url":"https://github.com/spatie/pixelmatch-php","last_synced_at":"2025-04-22T20:31:21.997Z","repository":{"id":193011443,"uuid":"687922985","full_name":"spatie/pixelmatch-php","owner":"spatie","description":"Compare images using PHP","archived":false,"fork":false,"pushed_at":"2025-02-03T04:56:13.000Z","size":657,"stargazers_count":45,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-16T01:51:31.900Z","etag":null,"topics":["images","php","pixelmatch"],"latest_commit_sha":null,"homepage":"https://spatie.be/open-source","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/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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":"spatie"}},"created_at":"2023-09-06T09:32:40.000Z","updated_at":"2025-04-11T05:04:37.000Z","dependencies_parsed_at":"2023-09-06T10:40:44.433Z","dependency_job_id":"ed9618ec-5d94-4bd4-bebf-ce4c61d3c9d4","html_url":"https://github.com/spatie/pixelmatch-php","commit_stats":null,"previous_names":["spatie/pixelmatch-php"],"tags_count":4,"template":false,"template_full_name":"spatie/package-skeleton-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fpixelmatch-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fpixelmatch-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fpixelmatch-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Fpixelmatch-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/pixelmatch-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250318698,"owners_count":21410981,"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":["images","php","pixelmatch"],"created_at":"2024-11-10T02:08:50.487Z","updated_at":"2025-04-22T20:31:21.752Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie"],"categories":[],"sub_categories":[],"readme":"# Compare images using PHP\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/pixelmatch-php.svg?style=flat-square)](https://packagist.org/packages/spatie/pixelmatch-php)\n[![Tests](https://github.com/spatie/pixelmatch-php/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/pixelmatch-php/actions/workflows/run-tests.yml)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/pixelmatch-php.svg?style=flat-square)](https://packagist.org/packages/spatie/pixelmatch-php)\n\nThis package can compare two images and return the percentage of matching pixels. It's a PHP wrapper around the [Pixelmatch](https://github.com/mapbox/pixelmatch) JavaScript library.\n\nHere's a quick example on how to use the package.\n\n```php\nuse Spatie\\Pixelmatch\\Pixelmatch;\n\n$pixelmatch = Pixelmatch::new(\"path/to/file1.png\", \"path/to/file2.png\");\n\n$pixelmatch-\u003ematchedPixelPercentage(); // returns a float, for example 97.5\n$pixelmatch-\u003emismatchedPixelPercentage(); // returns a float, for example 2.5\n```\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/pixelmatch-php.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/pixelmatch-php)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/pixelmatch-php\n```\n\nIn your project, or on your server, you must have the JavaScript package [`Pixelmatch`](https://github.com/mapbox/Pixelmatch) installed.\n\n```bash\nnpm install pixelmatch\n```\n\n... or Yarn.\n\n```bash\nyarn add pixelmatch\n```\n\nMake sure you have installed Node 16 or higher.\n\n## Usage\n\nHere's how you can get the percentage of matching pixels between two images.\n\n```php\nuse Spatie\\Pixelmatch\\Pixelmatch;\n\n$pixelmatch = Pixelmatch::new(\"path/to/file1.png\", \"path/to/file2.png\");\n\n$pixelmatch-\u003ematchedPixelPercentage(); // returns a float, for example 97.5\n$pixelmatch-\u003emismatchedPixelPercentage(); // returns a float, for example 2.5\n```\n\nTo get the amount of matched and mismatched pixels, you can use these methods.\n\n```php\nuse Spatie\\Pixelmatch\\Pixelmatch;\n\n$pixelmatch = Pixelmatch::new(\"path/to/file1.png\", \"path/to/file2.png\");\n\n$pixelmatch-\u003ematchedPixels(); // returns an int\n$pixelmatch-\u003emismatchedPixels(); // returns an int\n```\n\nYou can use the `matches function` to check if the images match.\n\n```php\nuse Spatie\\Pixelmatch\\Pixelmatch;\n\n$pixelmatch = Pixelmatch::new(\"path/to/file1.png\", \"path/to/file2.png\");\n$pixelmatch-\u003ematches(); // returns a boolean\n$pixelmatch-\u003edoesNotMatch(); // returns a boolean\n```\n\n### Setting a threshold\n\nTo set the threshold for the amount of mismatching pixels, you can use the `threshold` method. Higher values will make the comparison more sensitive. The threshold should be between 0 and 1. \n\nIf you don't set a threshold, we'll use the default value of `0.1`.\n\n```php\n$pixelmatch-\u003ethreshold(0.05);\n```\n\n### Ignoring anti-aliasing\n\nTo ignore anti-aliased pixels, you can use the `includeAa` method.\n\n```php\n$pixelmatch-\u003eincludeAa();\n```\n\n## Limitations\n\nThe package can only compare png images.\n\nImages with different dimensions cannot be compared. If you try to do this, a `Spatie\\Pixelmatch\\Exceptions\\CouldNotCompare` exception will be thrown.\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Niels Vanpachtenbeke](https://github.com/nielsvanpach)\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fpixelmatch-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Fpixelmatch-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Fpixelmatch-php/lists"}