我们的代码世界 / name-that-color
NTC JS 库的非官方 PHP 版本,用于查找最接近的颜色名称。
dev-master
2018-08-03 18:14 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-18 16:41:09 UTC
README
这个库是将已知的 JS 脚本移植为 PHP,通过十六进制代码查找最接近的颜色名称。
安装
Name That Color 可与或无需 Composer 使用。
使用 Composer
使用 name-that-color 的首选方式是结合 Composer。执行以下命令将此软件包作为项目依赖项安装
composer require ourcodeworld/name-that-color
不使用 Composer
如果您不使用 composer,仍然可以使用包装器。从存储库下载 ColorInterpreter.php 类,然后使用 require_once
在您的代码中导入它
<?php require_once("ColorInterpreter.php"); $instance = new ColorInterpreter(); // Configuration here ...
示例
包含 ColorInterpreter 类并调用返回由脚本提供的最接近颜色解释的数组的方法。结果数组包含三个键
- hex:类中最接近颜色的十六进制颜色。
- name:赋予颜色的名称。
- exact:布尔值,确定颜色代码是否与名称完全一致。
// Include the class use ourcodeworld\NameThatColor\ColorInterpreter as NameThatColor; $instance = new NameThatColor(); $result = $instance->name("#008559"); var_dump($result); array(3) { ["hex"]=> string(7) "#01826B" ["name"]=> string(8) "Deep Sea" ["exact"]=> bool(false) }
此类还提供其他实用工具,例如将十六进制颜色代码转换为 HSL 或 RGB,如果您需要它们
// Include the class use ourcodeworld\NameThatColor\ColorInterpreter as NameThatColor; $instance = new NameThatColor(); // From hex to HSL $hsl_data = $instance->hsl("#008559"); var_dump($hsl_data); array(3) { [0]=> int(113) [1]=> int(255) [2]=> int(66) } // From hex to RGB $rgb_data = $instance->rgb("#008559"); var_dump($rgb_data); array(3) { [0]=> int(0) [1]=> int(133) [2]=> int(89) }
MIT 许可证 (MIT)
版权所有 © 2017 Our Code World
特此授予任何人免费获得此软件及其相关文档文件(“软件”)的副本(以下简称“软件”)的权利,不受任何限制地处理软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件的副本,并允许向软件提供的人这样做,前提是遵守以下条件
上述版权声明和本许可声明应包含在所有副本或软件的大部分内容中。
软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、适用于特定目的和无侵权性保证。在任何情况下,作者或版权所有者不应对任何索赔、损害或其他责任负责,无论该索赔、损害或其他责任是基于合同、侵权或其他方式产生,是否与软件或软件的使用或其他交易有关。