All Projects → villfa → php-invert-color

villfa / php-invert-color

Licence: MIT License
Invert a given color.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to php-invert-color

type-reverse
🦄 Lightweight reverse utility around strings, arrays, numbers and more.
Stars: ✭ 30 (+130.77%)
Mutual labels:  reverse, inverse, invert
colored-console
🌈 Add some color to your console >_
Stars: ✭ 74 (+469.23%)
Mutual labels:  color, colour
colr pickr
Colr Pickr, a vanilla JavaScript color picker component built with SVGs, with features like saving colors. Similar design to the chrome-dev-tools color picker.
Stars: ✭ 27 (+107.69%)
Mutual labels:  color, colour
leeks.js
Simple ANSI styling for your terminal
Stars: ✭ 12 (-7.69%)
Mutual labels:  color, colour
tc-lib-color
PHP library to manipulate various color representations
Stars: ✭ 19 (+46.15%)
Mutual labels:  color, colour
dehex
🎨👀 R package: learn to assess a colour hex code by eye
Stars: ✭ 29 (+123.08%)
Mutual labels:  color, colour
shades
Simple colour manipulation in R
Stars: ✭ 70 (+438.46%)
Mutual labels:  color, colour
SAPC-APCA
APCA (Accessible Perceptual Contrast Algorithm) is a new method for predicting contrast for use in emerging web standards (WCAG 3) for determining readability contrast. APCA is derived form the SAPC (S-LUV Advanced Predictive Color) which is an accessibility-oriented color appearance model designed for self-illuminated displays.
Stars: ✭ 266 (+1946.15%)
Mutual labels:  color, luminance
prismatic
color manipulation R package Simply and Tidy
Stars: ✭ 121 (+830.77%)
Mutual labels:  color, colour
colour-notebooks
Colour - Jupyter Notebooks
Stars: ✭ 21 (+61.54%)
Mutual labels:  color, colour
colour
Validate colours.
Stars: ✭ 31 (+138.46%)
Mutual labels:  color, colour
Chromatism
🌈 A simple set of utility functions for colours.
Stars: ✭ 1,763 (+13461.54%)
Mutual labels:  color, colour
stellarized
✦ paint vim with the stars ✦
Stars: ✭ 70 (+438.46%)
Mutual labels:  color, colour
SwiftColorWheel
Delightful color picker wheel for iOS in Swift.
Stars: ✭ 37 (+184.62%)
Mutual labels:  color, colour
colour-nuke
Colour - Nuke
Stars: ✭ 145 (+1015.38%)
Mutual labels:  color, colour
icc
JavaScript module to parse International Color Consortium (ICC) profiles
Stars: ✭ 37 (+184.62%)
Mutual labels:  color, colour
MNIST-invert-color
Invert the color of MNIST images with PyTorch
Stars: ✭ 13 (+0%)
Mutual labels:  color, invert
a-color-picker
A color picker for web app
Stars: ✭ 97 (+646.15%)
Mutual labels:  color
DDHTweaks
Tweak UI elements at run time to find the perfect values
Stars: ✭ 27 (+107.69%)
Mutual labels:  color
unblending
Decomposing an input image into layers via "color unblending"
Stars: ✭ 125 (+861.54%)
Mutual labels:  color

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].