Skip to content

Commit 77e25ca

Browse files
author
Torben Köhn
committed
Minor README update
1 parent 97b331d commit 77e25ca

File tree

1 file changed

+77
-41
lines changed

1 file changed

+77
-41
lines changed

README.md

Lines changed: 77 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -61,41 +61,6 @@ $rgb = new RgbColor(0, 100, 0);
6161
$hsla = new HslaColor(120, .5, .1, 1.0);
6262
```
6363

64-
## Using a color in HTML
65-
66-
The colors mostly convert to their best CSS representation automatically when casted to a string.
67-
68-
```php
69-
echo Color::get('red'); //'rgb(255, 0, 0)'
70-
echo Color::get('hsl(120, .5, .2)'); //'hsl(120, 50%, 20%)'
71-
```
72-
73-
Given that some browsers don't support `hsl()` CSS colors, it's best to always convert to RGB or RGBA before casting to a string.
74-
75-
```php
76-
echo Color::get('red')->getRgba(); //rgba(255, 0, 0, 1)
77-
```
78-
79-
It's not automatically done to give you the ability to also use the `hsl()` writing style. We also don't know, if CSS will implement further color constructors in the future.
80-
81-
Notice that functions always convert to their respective class automatically, so doing things like
82-
83-
```php
84-
<div style="width: 100%; background: <?=Color::get('red')->withAlphaSupport()->withAlpha($alpha)?>;"></div>
85-
```
86-
87-
is absolutely valid, since you can assume the result will be an `RgbaColor` instance.
88-
89-
It can get even shorter by using
90-
91-
```php
92-
<div style="width: 100%; background: <?=Color::fade(Color::get('red'), $alpha)?>;"></div>
93-
```
94-
95-
Named colors will always return a `RgbColor` instance. Using `withAlphaSupport()` will always return the respective alpha-version of a color.
96-
97-
Also notice that Xyz and Lab don't have Alpha-versions and will just return an `RgbaColor`-instance of the same color.
98-
9964
## Color conversion
10065

10166
Every color can be converted to every other color space instantly.
@@ -109,16 +74,51 @@ $color->getLab()->getL();
10974
```
11075

11176

112-
Supported color spaces are:
77+
Here's a list of the supported color spaces with their respective value methods
11378

114-
- RGB (`getRgb()`)
79+
- RGB (`getRgb(): RgbColor`)
80+
- `getRed()`
81+
- `getGreen()`
82+
- `getBlue()`
83+
- `withAlphaSupport(): RgbaColor`
11584
- RGBA (`getRgba()`)
85+
- `getRed()`
86+
- `getGreen()`
87+
- `getBlue()`
88+
- `getAlpha()`
89+
- `withoutAlphaSupport(): RgbColor`
11690
- HSL (`getHsl()`)
91+
- `getHue()`
92+
- `getSaturation()`
93+
- `getLightness()`
94+
- `withAlphaSupport(): HslaColor`
11795
- HSLA (`getHsla()`)
96+
- `getHue()`
97+
- `getSaturation()`
98+
- `getLightness()`
99+
- `getAlpha()`
100+
- `withoutAlphaSupport(): HslColor`
118101
- HSV (`getHsv()`)
102+
- `getHue()`
103+
- `getSaturation()`
104+
- `getValue()`
105+
- `withAlphaSupport(): HsvaColor`
119106
- HSVA (`getHsva()`)
107+
- `getHue()`
108+
- `getSaturation()`
109+
- `getValue()`
110+
- `getAlpha()`
111+
- `withoutAlphaSupport(): HsvColor`
120112
- CIE XYZ (`getXyz()`)
113+
- `getX()`
114+
- `getY()`
115+
- `getZ()`
116+
- `withAlphaSupport(): RgbaColor`
121117
- CIE L\*a\*b\* (`getLab()`)
118+
- `getL()`
119+
- `getA()`
120+
- `getB()`
121+
- `withAlphaSupport(): RgbaColor`
122122

123123
The system is designed so that you _don't need to know_ in which color space you're getting your current color in. If you want to do modifications on a color, just convert it to the color space you need prior to that.
124124

@@ -209,11 +209,11 @@ Through the implementation of CIE XYZ, CIE L\*a\*b\* and the CIEDE2000 standard
209209
```php
210210
$red = Color::get('red'); //rgb(255, 0, 0)
211211

212-
Color::getDifference(Color::get('red'), Color::get('blue')); //52.878674140461
212+
Color::getDifference($red, Color::get('blue')); //52.878674140461
213213

214-
Color::getDifference(Color::get('red'), Color::get('maroon')); //25.857031489394
214+
Color::getDifference($red, Color::get('maroon')); //25.857031489394
215215

216-
Color::getDifference(Color::get('red'), Color::get('rgb(250, 0, 0)')); //1.0466353226581
216+
Color::getDifference($red, Color::get('rgb(250, 0, 0)')); //1.0466353226581
217217
```
218218

219219
To compare colors with a tolerance, you can use the `equals`-method
@@ -255,7 +255,7 @@ $palette = new SimplePalette([
255255
$palette[] = 'rgb(120, 35, 56)';
256256

257257
$palette[0]; //RgbColor(255, 0, 0)
258-
$palette[5]; //RgbColor(120, 35, 56)
258+
$palette[6]; //RgbColor(120, 35, 56)
259259
```
260260

261261

@@ -460,6 +460,42 @@ Palette::getHtml($palette, 4);
460460
This will yield the colors `blue` and `navy`. Reducing the required range
461461
on `filterSimilarColors` will yield more and different blue colors.
462462

463+
## Using a color in HTML
464+
465+
The colors mostly convert to their best CSS representation automatically when casted to a string.
466+
467+
```php
468+
echo Color::get('red'); //'rgb(255, 0, 0)'
469+
echo Color::get('hsl(120, .5, .2)'); //'hsl(120, 50%, 20%)'
470+
```
471+
472+
Given that some browsers don't support `hsl()` CSS colors, it's best to always convert to RGB or RGBA before casting to a string.
473+
474+
```php
475+
echo Color::get('red')->getRgba(); //rgba(255, 0, 0, 1)
476+
```
477+
478+
It's not automatically done to give you the ability to also use the `hsl()` writing style. We also don't know, if CSS will implement further color constructors in the future.
479+
480+
Notice that functions always convert to their respective class automatically, so doing things like
481+
482+
```php
483+
<div style="width: 100%; background: <?=Color::get('red')->withAlphaSupport()->withAlpha($alpha)?>;"></div>
484+
```
485+
486+
is absolutely valid, since you can assume the result will be an `RgbaColor` instance.
487+
488+
It can get even shorter by using
489+
490+
```php
491+
<div style="width: 100%; background: <?=Color::fade(Color::get('red'), $alpha)?>;"></div>
492+
```
493+
494+
Named colors will always return a `RgbColor` instance. Using `withAlphaSupport()` will always return the respective alpha-version of a color.
495+
496+
Also notice that Xyz and Lab don't have Alpha-versions and will just return an `RgbaColor`-instance of the same color.
497+
498+
463499
# Examples, Code, Contribution, Support
464500

465501
If you have questions, problems with the code or you want to contribue, either consult the [examples](https://github.com/Talesoft/phim/tree/master/tests/pragmatic), the [code](https://github.com/Talesoft/phim/tree/master/src/Phim), write an [issue](https://github.com/Talesoft/phim/issues) or [send me an E-Mail](mailto:[email protected]).

0 commit comments

Comments
 (0)