Giter Site home page Giter Site logo

php-invert-color's Introduction

php-invert-color

Build Status Quality Gate Status Latest Stable Version License PDS Skeleton

invert hex color code

Installation

composer require villfa/invert-color

Usage

Here a basic example:

<?php
require_once 'vendor/autoload.php';

use InvertColor\Color;
use InvertColor\Exceptions\InvalidColorFormatException;

try {
    echo Color::fromHex('#fff')->invert(); // #000000
} catch (InvalidColorFormatException $e) {
    echo 'Invalid color: ', $e->getValue();
}

Color::fromHex(string $color): Color - throws InvalidColorFormatException

  • $color: string Color in HEX string. Accepted formats: #000000, #000, 000000, 000
InvertColor\Color::fromHex('#fff')->invert(); // #000000

Color::fromRGB(array $rgb): Color - throws InvalidRGBException

  • $rgb: array Color as an array of RGB values.
InvertColor\Color::fromRGB([0, 255, 0])->invert(); // #ff00ff

Color::invert([bool $bw]): string

  • $bw: bool Optional. A boolean value indicating whether the output should be amplified to black (#000000) or white (#ffffff), according to the luminance of the original color.
InvertColor\Color::fromHex('#000')->invert(); // #ffffff
InvertColor\Color::fromHex('#282b35')->invert(); // #d7d4ca

// amplify to black or white
InvertColor\Color::fromHex('282b35')->invert(true); // #ffffff

Color::invertAsRGB([bool $bw]): array

  • $bw: bool Optional. A boolean value indicating whether the output should be amplified to black or white, according to the luminance of the original color.
InvertColor\Color::fromHex('#000')->invertAsRGB(); // [255, 255, 255]
InvertColor\Color::fromHex('#282b35')->invertAsRGB(); // [215, 212, 202]

// amplify to black or white
InvertColor\Color::fromHex('282b35')->invertAsRGB(true); // [255, 255, 255]

Color::invertAsObj([bool $bw]): Color

  • $bw: bool Optional. A boolean value indicating whether the output should be amplified to black or white, according to the luminance of the original color.
InvertColor\Color::fromHex('#000')->invertAsObj()->getHex(); // #ffffff
InvertColor\Color::fromHex('#282b35')->invertAsObj()->getRGB(); // [215, 212, 202]

// amplify to black or white
InvertColor\Color::fromHex('282b35')->invertAsObj(true)->getRGB(); // [255, 255, 255]

Color::getHex(): string

InvertColor\Color::fromHex('#FFF')->getHex(); // #ffffff

Color::getRGB(): array

InvertColor\Color::fromHex('#fff')->getRGB(); // [255, 255, 255]

Color::getLuminance(): float

InvertColor\Color::fromHex('#fff')->getLuminance(); // 1
InvertColor\Color::fromHex('#000')->getLuminance(); // 0

Color::isBright(): bool

InvertColor\Color::fromHex('#fff')->isBright(); // true
InvertColor\Color::fromHex('#000')->isBright(); // false

Color::isDark(): bool

InvertColor\Color::fromHex('#fff')->isDark(); // false
InvertColor\Color::fromHex('#000')->isDark(); // true

Tests

To validate and test the library:

composer run-script test

Acknowledgement

This library is a port of the JS package invert-color.

More resources:

License

MIT

php-invert-color's People

Contributors

villfa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

php-invert-color's Issues

Failure to Acknowledge const STR_PAD_LEFT

Hi, I really like this piece of software, but sometime in the past several months it stopped working. I am running in PHP 7.2 and my system is rejecting the constant STR_PAD_LEFT in https://github.com/villfa/php-invert-color/blob/master/src/Color.php.

The error message reads: [05-Jan-2020 23:08:20 UTC] PHP Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /home/thege0/vendor/villfa/invert-color/src/Color.php on line 16.

I am an advanced novice in webpage development and am just learning how to use GIT, so please excuse me for not being able to be anymore helpful.

Roddy at nudge.online

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.