{"id":36969907,"url":"https://github.com/breadthe/php-contrast","last_synced_at":"2026-01-13T21:41:54.871Z","repository":{"id":62496844,"uuid":"241775565","full_name":"breadthe/php-contrast","owner":"breadthe","description":"Helpers for generating accessible color pairs","archived":false,"fork":false,"pushed_at":"2023-09-05T13:31:01.000Z","size":24,"stargazers_count":6,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-11T19:34:16.864Z","etag":null,"topics":["color-pairs","contrast-ratio","generated-pairs","php","php-contrast"],"latest_commit_sha":null,"homepage":"https://mumu.pw/contrast","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/breadthe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-20T02:32:55.000Z","updated_at":"2025-03-09T08:49:19.000Z","dependencies_parsed_at":"2023-02-14T12:16:08.363Z","dependency_job_id":null,"html_url":"https://github.com/breadthe/php-contrast","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/breadthe/php-contrast","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/breadthe%2Fphp-contrast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/breadthe%2Fphp-contrast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/breadthe%2Fphp-contrast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/breadthe%2Fphp-contrast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/breadthe","download_url":"https://codeload.github.com/breadthe/php-contrast/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/breadthe%2Fphp-contrast/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28401058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: 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":["color-pairs","contrast-ratio","generated-pairs","php","php-contrast"],"created_at":"2026-01-13T21:41:54.226Z","updated_at":"2026-01-13T21:41:54.864Z","avatar_url":"https://github.com/breadthe.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Contrast Tools\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/breadthe/php-contrast.svg?style=flat-square)](https://packagist.org/packages/breadthe/php-contrast)\n[![Build Status](https://img.shields.io/travis/breadthe/php-contrast/master.svg?style=flat-square)](https://travis-ci.org/breadthe/php-contrast)\n[![Quality Score](https://img.shields.io/scrutinizer/g/breadthe/php-contrast.svg?style=flat-square)](https://scrutinizer-ci.com/g/breadthe/php-contrast)\n[![Total Downloads](https://img.shields.io/packagist/dt/breadthe/php-contrast.svg?style=flat-square)](https://packagist.org/packages/breadthe/php-contrast)\n\nProvides various utilities for working with color contrast.\n\nThe primary purpose is to facilitate easy generation of accessible (minimum 3.0 contrast ratio) hex color pairs. A variation of these tools restricts the generated colors to [TailwindCSS's](https://tailwindcss.com/) default palette.\n\nI've created a [demo page](https://mumu.pw/contrast) to show how color pairs can be generated by this package. \n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require breadthe/php-contrast\n```\n\n## Usage\n\nImport the class.\n\n```php\nuse Breadthe\\PhpContrast\\HexColor; // factory\n\nuse Breadthe\\PhpContrast\\HexColorPair; // hex pair utilities\n\nuse Breadthe\\PhpContrast\\TailwindColor; // Tailwind color pair utilities\n```\n\n## Check the contrast ratio between 2 colors\n\n```php\n$hexColorPair = HexColorPair::make(HexColor::make('000000'), HexColor::make('ffffff'));\n$hexColorPair-\u003eratio; // 21\n$hexColorPair-\u003efg; // '#000000'\n$hexColorPair-\u003ebg; // '#ffffff'\n```\n\n## Get a random color pair (with the resulting ratio), with minimum 3:1 contrast ratio\n\n```php\n$hexColorPair = HexColorPair::random();\n$hexColorPair-\u003eratio; // 3.8\n$hexColorPair-\u003efg-\u003ehex; // '#36097e'\n$hexColorPair-\u003efg-\u003ename; // null\n$hexColorPair-\u003ebg-\u003ehex; // '#ed4847'\n$hexColorPair-\u003ebg-\u003ename; // null\n```\n\n## Get a random color pair (with the resulting ratio), with minimum specified contrast ratio (but no less than 3:1)\n\n**⚠️ Warning** For performance reasons, the minimum requested contrast ratio is capped at 4.5, although the generated pairs can go up to the theoretical maximum 21:1 ratio.\n\n**⚠️ Caution** When chaining with `minContrast()`, make sure to use `getRandom()` instead of `random()`.\n\n```php\n$hexColorPair = HexColorPair::minContrast(4.5)-\u003egetRandom();\n$hexColorPair-\u003eratio; // 7.6\n$hexColorPair-\u003efg-\u003ehex; // '#0c402f'\n$hexColorPair-\u003efg-\u003ename; // null\n$hexColorPair-\u003ebg-\u003ehex; // '#badd73'\n$hexColorPair-\u003ebg-\u003ename; // null\n```\n\n## Get a random accessible sibling for the given color, with minimum specified contrast ratio (but no less than 3:1)\n\n```php\n// Minimum 3:1 contrast ratio\nHexColorPair::sibling('000000')-\u003ehex; // '#ffffff'\n\n// Minimum specified contrast ratio (no less than 3:1)\nHexColorPair::minContrast(4.5)-\u003egetSibling('000000')-\u003ehex; // '#ffffff'\n```\n\n## Generate a random TailwindCSS color\n\n```php\n$twColor = TailwindColor::random();\n$twColor-\u003ehex; // '#e2e8f0'\n$twColor-\u003ename; // 'gray-300'\n```\n\n## Generate a pair of random accessible TailwindCSS colors\n\n```php\n$twColorpair = TailwindColor::randomPair();\n$twColorpair-\u003eratio; // 3.3\n$twColorpair-\u003efg-\u003ehex; // '#63b3ed'\n$twColorpair-\u003efg-\u003ename; // 'blue-400'\n$twColorpair-\u003ebg-\u003ehex; // '#4a5568'\n$twColorpair-\u003ebg-\u003ename; // 'green-700'\n```\n\n## Generate a pair of random accessible TailwindCSS colors, with minimum specified contrast ratio (but no less than 3:1)\n\n**⚠️ Warning** For performance reasons, the minimum requested contrast ratio is capped at 4.5, although the generated pairs can go up to the theoretical maximum 21:1 ratio.\n\n**⚠️ Caution** When chaining with `minContrast()`, make sure to use `getRandomPair()` instead of `randomPair()`.\n\n```php\n$twColorpair = TailwindColor::minContrast(4.5)-\u003egetRandomPair();\n$twColorpair-\u003eratio; // 7.0\n$twColorpair-\u003efg-\u003ehex; // '#faf5ff'\n$twColorpair-\u003efg-\u003ename; // 'purple-100'\n$twColorpair-\u003ebg-\u003ehex; // '#9b2c2c'\n$twColorpair-\u003ebg-\u003ename; // 'red-800'\n```\n\n## Merge the default Tailwind colors with a custom palette\n\nYou may extend the default Tailwind colors with your own custom palette. Here's an example of how to import a custom palette from a JSON file.\n\n```json\n{\n    \"background\": \"#FFFFFF\",\n    \"headline\": \"#1f1235\",\n    \"sub-headline\": \"#1b1425\",\n    \"button\": \"#ff6e6c\",\n    \"button-text\": \"#1f1235\"\n}\n```\n\n```php\n$customPalette = json_decode(file_get_contents('custom-palette.json'), true);\n\n$colors = TailwindColor::merge($customPalette)-\u003egetColors();\n```\n\n### Testing\n\n``` bash\ncomposer test\n```\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Security\n\nIf you discover any security related issues, please email omigoshdev@protonmail.com instead of using the issue tracker.\n\n## Credits\n\n- [Omigosh Dev](https://github.com/breadthe)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n## PHP Package Boilerplate\n\nThis package was generated using the [PHP Package Boilerplate](https://laravelpackageboilerplate.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbreadthe%2Fphp-contrast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbreadthe%2Fphp-contrast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbreadthe%2Fphp-contrast/lists"}