Wallogit.com
2017 © Pedro Peláez
A pointless PHP library for getting the mean and glow background colors of an image or icon.
Backlight is a pointless script inspired by the Ubuntu Unity Launcher. It will take an image/icon, and find it's mean background color as well as it's glow color. It will return an object with values in both RGB and HEX format for use., (*1)
The recommended way to install Backlight is through composer., (*2)
Just create a composer.json file for your project:, (*3)
{
"minimum-stability" : "dev",
"require": {
"tyler-king/backlight": "dev-master"
}
}
And run these two commands to install it:, (*4)
$ curl -s http://getcomposer.org/installer | php $ php composer.phar install
Now you can add the autoloader, and you will have access to the library:, (*5)
<?php require 'vendor/autoload.php';
The usage is pretty stright forward, very chainable (see the source). This is a basic example below., (*6)
<?php
use TylerKing\Backlight\Backlight;
$backlight = new Backlight('chrome-icon.png');
print_r($backlight->getBackground()); // Returns the RGB and HEX of the background to use.
print_r($backlight->getMean()); // Returns the RGB and HEX of the outter glow to use.
By running print_r or var_dump you will receieve an output containing the mean
background-color and the glow color for the icon or image., (*7)
stdClass Object
(
[background] => stdClass Object
(
[rgb] => Array
(
[0] => 192
[1] => 123
[2] => 18
)
[hex] => #c07b12
)
[glow] => stdClass Object
(
[rgb] => Array
(
[0] => 229
[1] => 146
[2] => 22
)
[hex] => #e59216
)
)
You can also pointlessly convert the image to pure HTML/CSS., (*8)
<?php
use TylerKing\Backlight\Backlight;
$backlight = new Backlight('chrome-icon.png');
file_put_contents('image.html', $backlight->toHTML());
By opening image.html in your browser you will now see the image in HTML/CSS format., (*9)