Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

Contrast Ratio Calculator

Accessibility library that calculates contrast ratios of colors as well as rates the contrast ratio against WCAG standards.

Getting started

  1. PHP 7.1.x is required
  2. Install the Contrast Ratio Calculator using Composer (recommended) or manually

Composer Installation

  1. Get Composer
  2. Install with composer require harmstyler/contrast-ratio-calculator
  3. 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/

About

Accessibility library that calculates contrast ratios of colors as well as rates the contrast ratio against WCAG standards.

Topics

Resources

License

Packages

No packages published

Languages