liquidpineapple / color
A micro PHP package to convert and alter colors! ?
Installs: 7 574
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 4
Open Issues: 0
Requires
- php: ^7.1
Requires (Dev)
- codeclimate/php-test-reporter: ^0.4.4
- infection/infection: ^0.10.5
- phpunit/phpunit: ^6.2
This package is not auto-updated.
Last update: 2020-05-18 12:15:56 UTC
README
A micro PHP package to convert and alter colors! 🔥
Contents of this document:
Installation
You can install this package through composer. To install the latest version in to your project use the following command:
composer require liquidpineapple/color
This package requires PHP 7.0 or higher.
Documentation
Table of contents:
-
b) Output
a) Types
-
a) Lightness
b) Saturation
1. Conversion
You can use this package to convert colors to different notations. An example might be converting HEX to RGB:
<?php use Liquidpineapple\Color; $rgbColor = Color::fromHEX('#1E90FF')->toRGB(); // [30, 144, 255]
1a. Output
In some cases you might want an output like rgb(30, 144, 255)
. This can be done using the following method:
<?php use Liquidpineapple\Color; $rgbColor = Color::fromHEX('#1E90FF')->toRGBString(); // rgb(30, 144, 255)
1b. Types
You can convert from the following types:
- HEX:
fromHEX($hex)
- RGB:
fromHEX($red, $green, $blue)
- HSL:
fromHSL($hue, $saturation, $lightness)
- HSV:
fromHSV($hue, $saturation, $value)
To the following types
- HEX:
toHEX()
&toHEXString()
(alias oftoHEX()
) - RGB:
toRGB()
&toRGBString()
- HSL:
toHSL()
&toHSLString()
- HSV:
toHSV()
&toHSVString()
2. Alteration
Sometimes just conversion isn't enough, in some cases you might want to darken or saturate a color. Luckily, this is a breeze with this package.
2a. Lightness
You can alter the lightness of the color using the following methods:
lighten($amount)
darken($amount)
The amount in both message is a percentage. An example:
<?php use Liquidpineapple\Color; $primaryColor = '#1E90FF'; $secondaryColor = Color::fromHEX('#1E90FF')->darken(10)->toHEX(); // #2A8FF4
2b. Saturation
Just as with lightness you can alter the saturation of a given color. This can be done using the following methods:
saturate($amount)
desaturate($amount)
The amount in both message is a percentage. An example:
<?php use Liquidpineapple\Color; $dullColor = '#C44'; $exitingColor = Color::fromHEX('#C44')->saturate(10)->toHEX(); // #D33C3C
Contributing
Did we miss something, or do you have cool ideas? Feel free to contribute!
How to contribute:
- Fork this repository.
- Write code (with comments).
- Write tests (100% coverage).
- Create a pull-request.
- Profit!