File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ Palette for PHP
2
+ ===============
3
+
4
+ ![ Logo] ( docs/artwork.png )
5
+
6
+ ** Palette** is a port of the Android library of the same name, for extracting a colour palette from an image. The
7
+ results can then be used for tinting the interface to match the image.
8
+
9
+ Usage
10
+ -----
11
+ Palette makes use of the [ Intervention image library] ( https://github.com/Intervention/image ) to load images, and supports
12
+ both the Imagick and GD drivers. The performance of the Imagick driver is slightly better, but the difference is fairly small.
13
+
14
+ ``` php
15
+ $manager = new ImageManager(array('driver' => 'imagick'));
16
+ $image = $manager->make('path/to/image.png');
17
+
18
+ $palette = Palette::generate($image);
19
+ echo $palette->getVibrantSwatch()->getColor();
20
+ ``
21
+
22
+ Contrast
23
+ --------
24
+ You can get the contrast of a colour on a non-translucent background by calling
25
+ `AbstractColor::calculateContrast($background, $foreground)`. Information on the recommended contrast ratio can be found
26
+ at [the W3C recommendation](http://www.w3.org/TR/WCAG/#visual-audio-contrast-contrast).
27
+
28
+ ```php
29
+ $white = new RGBColor(1, 1, 1);
30
+ $black = new RGBColor(0, 0, 0);
31
+ $background = $palette->getVibrantSwatch()->getColor();
32
+
33
+ echo '<div style =" background : ' . $background . ' " >';
34
+ if(AbstractColor::calculateContrast($background, $white) >= 3) {
35
+ echo '<h1 style =" color : white ;" >Palette</h1 >';
36
+ } else {
37
+ echo '<h1 style =" color : black ;" >Palette</h1 >';
38
+ }
39
+ echo '</div >';
40
+ ```
You can’t perform that action at this time.
0 commit comments