PHP code example of davidgorges / color-contrast-php
1. Go to this page and download the library: Download davidgorges/color-contrast-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
davidgorges / color-contrast-php example snippets
use ColorContrast\ColorContrast;
/* ... */
$contrast = new ColorContrast();
$contrast->addColors(0xff0000, 0x002200, 0x0022ff, 0xffffff);
$combinations = $contrast->getCombinations(ColorContrast::MIN_CONTRAST_AAA);
foreach ($combinations as $combination) {
printf("#%s on the Background color #%s has a contrast value of %f \n", $combination->getForeground(), $combination->getBackground(), $combination->getContrast());
}
$contrast = new ColorContrast();
// imagine having a red background and you need to know if its better
// to display a white or black text on top if it
$complimentary = $contrast->complimentaryTheme('#d80000'); // returns ColorContrast::DARK to indicate you should use a dark color on this background
if($complimentary == ColorContrast::LIGHT) {
// Use a light font
} else {
// use a dark font
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.