Skip to content

Commit f702b96

Browse files
committed
Add readme
1 parent 330b925 commit f702b96

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
```

docs/artwork.png

690 KB
Loading

0 commit comments

Comments
 (0)