popphp/pop-color
最新稳定版本:1.0.3
Composer 安装命令:
composer require popphp/pop-color
包简介
Pop Color Component for Pop PHP Framework
关键字:
README 文档
README
Overview
Pop Color is a helpful component to manage different types of color values and conversions. Supported color formats include:
- RGB
- HEX
- HSL
- CMYK
- Grayscale
Within the Pop PHP Framework, the pop-css, pop-image and pop-pdf components use this component.
Install
Install pop-color using Composer.
composer require popphp/pop-color
Or, require it in your composer.json file
"require": {
"popphp/pop-color" : "^1.0.3"
}
Quickstart
Create a color object
$rgb = Color::rgb(120, 60, 30, 0.5); echo $rgb . PHP_EOL;
The above command will print the default CSS format:
rgba(120, 60, 30, 0.5)
Convert to another color format
$hex = $rgb->toHex(); echo $hex . PHP_EOL;
#783c1e
$hsl = $hex->toHsl(); echo $hsl . PHP_EOL;
hsl(20, 75%, 47%)
// Will print a string of space-separated values, common to the PDF color string format $cmyk = $rgb->toCmyk(); echo $cmyk . PHP_EOL;
0 0.5 0.75 0.53
Accessing Color Properties
$rgb = Color::rgb(120, 60, 30, 0.5); echo $rgb->getR() . PHP_EOL; echo $rgb->getG() . PHP_EOL; echo $rgb->getB() . PHP_EOL; echo $rgb->getA() . PHP_EOL;
120
60
30
0.5
$cmyk = Color::cmyk(60, 30, 20, 50); echo $cmyk->getC() . PHP_EOL; echo $cmyk->getM() . PHP_EOL; echo $cmyk->getY() . PHP_EOL; echo $cmyk->getK() . PHP_EOL;
60
30
20
50
Parse Color Strings
$rgb = Color::parse('rgba(120, 60, 30, 0.5)'); echo $rgb->getR() . PHP_EOL; echo $rgb->getG() . PHP_EOL; echo $rgb->getB() . PHP_EOL; echo $rgb->getA() . PHP_EOL; echo $rgb . PHP_EOL;
120
60
30
0.5
rgba(120, 60, 30, 0.5)
统计信息
- 总下载量: 3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2023-10-17