Giter Site home page Giter Site logo

color-contrast-php's Introduction

ColorContrast

Small library to find valid color combinations for a given contrast threshold. The contrast calculation algorithm is based on the WCAG 2.0.

Build Status Latest Stable Version Total Downloads License PHPStan Enabled


Install

Using composer:

composer require davidgorges/color-contrast

Usage

    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());
    }

this would output:

    #FFFFFF on the Background color #002200 has a contrast value of 17.949476
    #FFFFFF on the Background color #0022FF has a contrast value of 8.033817
    #002200 on the Background color #FFFFFF has a contrast value of 17.949476
    #0022FF on the Background color #FFFFFF has a contrast value of 8.033817

Dark or Light Complimentary Color

    $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
    }

Thanks

License

The MIT License (MIT)

Copyright (c) 2015 David Gorges

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

color-contrast-php's People

Contributors

davidgorges avatar dependabot-preview[bot] avatar dependabot[bot] avatar frugan-dev avatar jpuck avatar willrowe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

color-contrast-php's Issues

Dependabot can't resolve your PHP dependency files

Dependabot can't resolve your PHP dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - phpunit/phpunit 8.3.4 requires php ^7.2 -> your PHP version (7.3.8-1+ubuntu18.04.1+deb.sury.org+1) overridden by "config.platform.php" version (5.4) does not satisfy that requirement.
    - phpunit/phpunit 8.3.3 requires php ^7.2 -> your PHP version (7.3.8-1+ubuntu18.04.1+deb.sury.org+1) overridden by "config.platform.php" version (5.4) does not satisfy that requirement.
    - phpunit/phpunit 8.3.2 requires php ^7.2 -> your PHP version (7.3.8-1+ubuntu18.04.1+deb.sury.org+1) overridden by "config.platform.php" version (5.4) does not satisfy that requirement.
    - phpunit/phpunit 8.3.1 requires php ^7.2 -> your PHP version (7.3.8-1+ubuntu18.04.1+deb.sury.org+1) overridden by "config.platform.php" version (5.4) does not satisfy that requirement.
    - phpunit/phpunit 8.3.0 requires php ^7.2 -> your PHP version (7.3.8-1+ubuntu18.04.1+deb.sury.org+1) overridden by "config.platform.php" version (5.4) does not satisfy that requirement.
    - phpunit/phpunit 8.2.5 requires php ^7.2 -> your PHP version (7.3.8-1+ubuntu18.04.1+deb.sury.org+1) overridden by "config.platform.php" version (5.4) does not satisfy that requirement.
    - phpunit/phpunit 8.2.4 requires php ^7.2 -> your PHP version (7.3.8-1+ubuntu18.04.1+deb.sury.org+1) overridden by "config.platform.php" version (5.4) does not satisfy that requirement.
    - phpunit/phpunit 8.2.3 requires php ^7.2 -> your PHP version (7.3.8-1+ubuntu18.04.1+deb.sury.org+1) overridden by "config.platform.php" version (5.4) does not satisfy that requirement.
    - phpunit/phpunit 8.2.2 requires php ^7.2 -> your PHP version (7.3.8-1+ubuntu18.04.1+deb.sury.org+1) overridden by "config.platform.php" version (5.4) does not satisfy that requirement.
    - phpunit/phpunit 8.2.1 requires php ^7.2 -> your PHP version (7.3.8-1+ubuntu18.04.1+deb.sury.org+1) overridden by "config.platform.php" version (5.4) does not satisfy that requirement.
    - phpunit/phpunit 8.2.0 requires php ^7.2 -> your PHP version (7.3.8-1+ubuntu18.04.1+deb.sury.org+1) overridden by "config.platform.php" version (5.4) does not satisfy that requirement.
    - Installation request for phpunit/phpunit ^8.2 -> satisfiable by phpunit/phpunit[8.2.0, 8.2.1, 8.2.2, 8.2.3, 8.2.4, 8.2.5, 8.3.0, 8.3.1, 8.3.2, 8.3.3, 8.3.4].

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

You can mention @dependabot in the comments below to contact the Dependabot team.

Your requirements could not be resolved to an installable set of packages.

You're currently requiring a development branch of a package.

For others to use color-contrast-php in their projects, they must declare a dev minimum stability because composer defaults to stable, otherwise they'll get a dependency resolution conflict during installation.

Alternatively, you could try to convince @mikeemoo to make a release tag for ColorJizz-PHP and require that as a stable version. Or fork it, make your own release, and then require that version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.