scripturadesign/color
Composer 安装命令:
composer require scripturadesign/color
包简介
Working with colors
关键字:
README 文档
README
Color is a package to convert between color types.
Install
Via Composer
$ composer require scripturadesign/color
Usage
HEX
Hexadecimal
$hex = new \Scriptura\Color\Types\HEX('ff0000'); // New HEX color $hex = new \Scriptura\Color\Types\HEX('ff0000', '#{code}'); // New HEX color with template echo $hex->code(); // 'FF0000' echo $hex; // '#FF0000' echo $hex->withTemplate('color: #{code};'); // 'color: #FF0000;' $hex = $hex->toHEX(); // Convert the color to \Scriptura\Color\Types\HEX $rgb = $hex->toRGB(); // Convert the color to \Scriptura\Color\Types\RGB $hsl = $hex->toHSL(); // Convert the color to \Scriptura\Color\Types\HSL $c256 = $hex->to256(); // Convert the color to \Scriptura\Color\Types\C256
Default template
#{code}
Sanitizing
HEX does some sanitizing to support all the various ways a hex color can be written.
Example:
123 => '112233'
987654 => '987654'
'aBc' => 'AABBCC'
'FeDcBa' => 'FEDCBA'
'#1B5' => '11BB55'
'#1a2b3c' => '1A2B3C'
RGB
Red, Green, Blue
$rgb = new \Scriptura\Color\Types\RGB(255, 0, 0); // New RGB color $rgb = new \Scriptura\Color\Types\RGB(255, 0, 0, '{red},{green},{blue}'); // New RGB color with template echo $rgb->red(); // 255 echo $rgb->green(); // 0 echo $rgb->blue(); // 0 echo $rgb->rgb(); // [255, 0, 0] echo $rgb; // '255,0,0' echo $rgb->withTemplate('color: rgb({red}, {green}, {blue});'); // 'color: rgb(255, 0, 0);' $rgb = $rgb->withRed(0); // New instance with red set to 0 $rgb = $rgb->withGreen(255); // New instance with green set to 255 $rgb = $rgb->withBlue(255); // New instance with blue set to 255 $hex = $rgb->toHEX(); // Convert the color to \Scriptura\Color\Types\HEX $rgb = $rgb->toRGB(); // Convert the color to \Scriptura\Color\Types\RGB $hsl = $rgb->toHSL(); // Convert the color to \Scriptura\Color\Types\HSL $c256 = $rgb->to256(); // Convert the color to \Scriptura\Color\Types\C256
Default template
{red},{green},{blue}
HSL
Hue, Saturation, Lightness
$hsl = new \Scriptura\Color\Types\HSL(0, 100, 50); // New HSL color $hsl = new \Scriptura\Color\Types\HSL(0, 100, 50, '{hue}° {saturation}% {lightness}%'); // New HSL color with template echo $hsl->hue(); // 0 echo $hsl->saturation(); // 100 echo $hsl->lightness(); // 50 echo $hsl->hsl(); // [0, 100, 50] echo $hsl; // '0° 100% 50%' echo $hsl->withTemplate('color: ({hue}, {saturation}%, {lightness}%);'); // 'color: hsl(0, 100%, 50%);' $hsl = $hsl->withHue(180); // New instance with hue set to 180 $hsl = $hsl->withSaturation(50); // New instance with saturation set to 50 $hsl = $hsl->withLightness(25); // New instance with lightness set to 25 $hex = $hsl->toHEX(); // Convert the color to \Scriptura\Color\Types\HEX $rgb = $hsl->toRGB(); // Convert the color to \Scriptura\Color\Types\RGB $hsl = $hsl->toHSL(); // Convert the color to \Scriptura\Color\Types\HSL $c256 = $hsl->to256(); // Convert the color to \Scriptura\Color\Types\C256 $hsl = $hsl->lighten(10); // New instance that is lightened by 10% $hsl = $hsl->darken(10); // New instance that is darkened by 10% $hsl = $hsl->saturate(10); // New instance that is saturated by 10% $hsl = $hsl->desaturate(10); // New instance that is desaturated by 10% $mix = $hsl->mix(new \Scriptura\Color\Types\HSL(120, 100, 50)); // Get a new color that is a mix between two colors
Default template
{hue}° {saturation}% {lightness}%
256
Terminal 256-color
000 - 007: standard colors008 - 015: high intensity colors016 - 231: 216 colors232 - 255: grayscale (black to white) https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
$c256 = new \Scriptura\Color\Types\C256(196); // New 256 color $c256 = new \Scriptura\Color\Types\C256(196, '{code}'); // New 256 color with template echo $c256->code(); // 196 echo $c256; // '196' echo $c256->withTemplate('\e[48;{code}m'); // '\e[48;196m' $hex = $c256->toHEX(); // Convert the color to \Scriptura\Color\Types\HEX $rgb = $c256->toRGB(); // Convert the color to \Scriptura\Color\Types\RGB $hsl = $c256->toHSL(); // Convert the color to \Scriptura\Color\Types\HSL $c256 = $c256->to256(); // Convert the color to \Scriptura\Color\Types\C256
Default template
{code}
Change log
Please see [CHANGELOG][link-changelog] for more information what has changed recently.
Testing
The test suite can be run with the following composer script.
$ composer test
Contributing and Forking
Please note that this project is licensed under the MIT license. We encourage forking of this project, but ask that you keep all copyright, attribution notices, and continue to use the MIT license in your fork of the project.
For further details on Contributing guidelines, please read the contributing guide.
Security
If you discover any security related issues, please email martindilling@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
scripturadesign/color 适用场景与选型建议
scripturadesign/color 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 73.93k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 08 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「color」 「rgb」 「hsl」 「hex」 「terminal color」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 scripturadesign/color 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 scripturadesign/color 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 scripturadesign/color 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An image and color manipulation and processing library for PHP
Package for manipulating colors in multiple color spaces.
Native (browser) color input field for SilverStripe
The PHP Average Color Picker Library
Generates QR Codes
Colorizes the Flarum forum header and interface based on the active tag's color.
统计信息
- 总下载量: 73.93k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-08-01