kennwilson/colormap-php

语言: PHP

git: https://github.com/kennwilson/colormap-php

Colormap提供了一种在十六进制,RGB和命名颜色之间转换HTML颜色的简便方法。
Colormap provides an easy way to convert HTML colors between hexadecimal, RGB, and named colors.
README.md (中文)

Colormap(PHP)

作者:肯恩威尔逊 作者网址:http://www.kennwilson.com/

描述

Colormap提供了辅助方法,用于在Web上使用的不同格式之间转换颜色。支持的格式是:

  • 六字符十六进制(例如,#000000)
  • 三字符十六进制(例如,#000)
  • RGB(例如,rgb(0,0,0))
  • HTML命名颜色,包括非W3C颜色(例如,黑色)

三个字符十六进制代码标准化为六个字符,所有输入标准化为小写。颜色可以从这些格式中的任何一种转换为任何其他格式。

该库是从Hextractor中提取的。

用法

包含类并实例化ColorMap对象:

include_once "colormap.php";
$map = new ColorMap();

根据需要调用各种方法:

$hex  = $map->rgb_to_hex('119 125 66');        // Returns '#777d42'
$rgb  = $map->hex_to_rgb('#777d42', 'string'); // Returns '119 125 66'
$name = $map->hex_to_name('#ffffff');          // Returns 'white'

执照

此代码根据MIT许可条款发布,可以出于任何目的免费使用和重新分发。如果您发现此代码有用,返回我的网站的链接会很酷,但不是必需的。

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

Colormap (PHP)

Author: Kenn Wilson
Author URL: http://www.kennwilson.com/

Description

Colormap provides helper methods to convert colors between different formats used on the web. Supported formats are:

  • Six-character hexadecimal (eg, #000000)
  • Three-character hexadecimal (eg, #000)
  • RGB (eg, rgb(0,0,0))
  • HTML named color, including non-W3C colors (eg, black)

Three character hex codes are normalized to six characters and all input is normalized to lowercase. Colors can be converted from any one of these formats to any other.

This library was extracted from Hextractor.

Usage

Include class and instantiate a ColorMap object:

include_once "colormap.php";
$map = new ColorMap();

Call various methods, as needed:

$hex  = $map->rgb_to_hex('119 125 66');        // Returns '#777d42'
$rgb  = $map->hex_to_rgb('#777d42', 'string'); // Returns '119 125 66'
$name = $map->hex_to_name('#ffffff');          // Returns 'white'

License

This code is released under the terms of the MIT License and is free to use and redistribute for any purpose. If you find this code helpful, a link back to my site would be cool, but it’s not required.