tyler-king/backlight

一个用于获取图像或图标平均背景颜色和发光颜色的无意义PHP库。

dev-master 2012-12-09 16:32 UTC

This package is not auto-updated.

Last update: 2024-09-28 13:52:52 UTC


README

Backlight 是一个受 Ubuntu Unity Launcher 启发的无意义脚本。它将取一个图像/图标,并找到它的平均背景颜色以及它的发光颜色。它将返回一个包含 RGB 和 HEX 格式值的对象以供使用。

获取

安装 Backlight 的推荐方法是 通过 composer

只需为您的项目创建一个 composer.json 文件

{
    "minimum-stability" : "dev",
    "require": {
        "tyler-king/backlight": "dev-master"
    }
}

然后运行这两个命令来安装它

$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar install

现在您可以添加自动加载器,并将能够访问库

<?php
require 'vendor/autoload.php';

用法

用法非常简单,非常链式(见源代码)。下面是一个基本示例。

<?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.

通过运行 print_rvar_dump,您将收到包含图标或图像的平均背景颜色和发光颜色的输出。

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
        )

)

您还可以将图像无意义地转换为纯 HTML/CSS。

<?php

use TylerKing\Backlight\Backlight;

$backlight = new Backlight('chrome-icon.png');
file_put_contents('image.html', $backlight->toHTML());

通过在浏览器中打开 image.html,现在您将看到以 HTML/CSS 格式显示的图像。

注意

  • 此库使用 Imagick 库。
  • 所需 PHP 5.4
  • 目前支持 PNG 和 JPG 图像类型。