PHP Classes

PHP WCAG Color Compliance: Get the contrast ratio between two colors for WCAG

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 90 This week: 1All time: 9,925 This week: 571Up
Version License PHP version Categories
wcag-colour-complian 1.0.0Free For Educatio...5PHP 5, Graphics
Description 

Author

This package can get the contrast ratio between two colors.

It takes as parameters the values of two colors in RGB format.

The class can calculate the contrast ratio between two colors, as well the result of several tests of accessibility compliant with the WCAG standard.

Innovation Award
PHP Programming Innovation award nominee
April 2019
Number 9
Determining what colors contrast better with a given color may be important for applications that may need to display text or other graphics that use a given color in a background that uses another color.

This package can get the contrast ratio between two colors according to the Web Content Accessibility Guidelines (WCAG).

Manuel Lemos
Picture of Andrew Collington
  Performance   Level  
Name: Andrew Collington <contact>
Classes: 16 packages by
Country: United Kingdom
Age: 49
All time rank: 563 in United Kingdom
Week rank: 420 Down10 in United Kingdom Down
Innovation award
Innovation award
Nominee: 3x

Example

<?php

require './wcag.php';

echo
"===== Compatibility checks =====\n";
var_dump(WCAG::accessibility('013035', 'F2C75C'));
var_dump(WCAG::accessibility('1E428A', 'C284A3'));
var_dump(WCAG::accessibility('D6D2C4', 'FFE900'));
var_dump(WCAG::accessibility('FF9966', '000000'));
var_dump(WCAG::accessibility('FFFFFF', [0, 0, 0]));
var_dump(WCAG::accessibility([255, 255, 255], '#000'));

echo
"===== Luminance =====\n";
echo
WCAG::luminance('013035') . "\n";
echo
WCAG::luminance('1E428A') . "\n";
echo
WCAG::luminance('D6D2C4') . "\n";
echo
WCAG::luminance('FF9966') . "\n";
echo
WCAG::luminance('FFFFFF') . "\n";
echo
WCAG::luminance('000000') . "\n";

echo
"===== Contrast ratio =====\n";
echo
WCAG::contrastRatio('013035', 'F2C75C') . "\n";
echo
WCAG::contrastRatio('1E428A', 'C284A3') . "\n";
echo
WCAG::contrastRatio('D6D2C4', 'FFE900') . "\n";
echo
WCAG::contrastRatio('FF9966', '000000') . "\n";
echo
WCAG::contrastRatio('FFFFFF', [0, 0, 0]) . "\n";
echo
WCAG::contrastRatio([255, 255, 255], '#000') . "\n";

echo
"===== Hex to RGB =====\n";
var_dump(WCAG::hex2rgb('#013035'));
var_dump(WCAG::hex2rgb('1E428A'));
var_dump(WCAG::hex2rgb('#D6D2C4'));
var_dump(WCAG::hex2rgb('FF9966'));
var_dump(WCAG::hex2rgb('#FFF'));
var_dump(WCAG::hex2rgb('#000'));
var_dump(WCAG::hex2rgb('FFFFFF'));
var_dump(WCAG::hex2rgb('000000'));


  Files folder image Files  
File Role Description
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file wcag-example.js Data Auxiliary data
Accessible without login Plain text file wcag-example.php Example Auxiliary script
Accessible without login Plain text file wcag.js Data Auxiliary data
Plain text file wcag.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:90
This week:1
All time:9,925
This week:571Up