harmstyler / contrast-ratio-calculator
Calculate contrast ratios of colors.
Installs: 6 497
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2024-12-28 04:15:41 UTC
README
Accessibility library that calculates contrast ratios of colors as well as rates the contrast ratio against WCAG standards.
Getting started
- PHP 7.1.x is required
- Install the Contrast Ratio Calculator using Composer (recommended) or manually
Composer Installation
- Get Composer
- Install with
composer require harmstyler/contrast-ratio-calculator
- Add the following to your application's main PHP file:
require 'vendor/autoload.php'
;
Usage
<?php use HarmsTyler\ContrastRatioCalculator\Color; use HarmsTyler\ContrastRatioCalculator\ContrastRatio; use HarmsTyler\ContrastRatioCalculator\WCAGContrastRating; $primaryColor = new Color(); $primaryColor->setHex('#ffffff'); $secondaryColor = new Color(); $secondaryColor->setHex('#000000'); $contrastRatio = new ContrastRatio($primaryColor, $secondaryColor); echo $contrastRatio->getRatio(); // floating decimal point of calculated ratio $rating = new WCAGContrastRating(); echo $rating->rateContrastRatio($contrastRatio); // the WCAGContrast grade, either 'fail', 'aa-large', 'aa', or 'aaa'
Run the tests
./vendor/bin/phpunit tests/