phpexperts/color-speaker
Composer 安装命令:
composer require phpexperts/color-speaker
包简介
An easy-to-use converter for different types of color models.
README 文档
README
ColorSpeaker is a PHP Experts, Inc., Project is an easy-to-use converter for different types of color models.
It aims to support all major color models: RGB, CSS hex codes, HSL and HSV.
Installation
Via Composer
composer require phpexperts/color-speaker
Usage
Initialize it with 3 standard RGB integers:
$rgbSpeaker = ColorSpeaker::fromRGB(123, 111, 55); $hexSpeaker = ColorSpeaker::fromHexCode('#7B6F37'); $hslSpeaker = ColorSpeaker::fromHSL(49, 38, 35);
It can easily be used as a string for css-compatible output:
$csv = ".box { background-color: $rgbSpeaker; }"; // .box { background-color: rgb(123, 111, 55); } $csvHex = ".box { background-color: $hexSpeaker; }"; // .box { background-color: #7B6F37; }
You can also fetch the RGBColor and the HexColor directly:
$rgbColor = $rgbSpeaker->toRGB(); /* (string) $rgbColor === rgb(123, 111, 55); SimpleDTO => { 'red' => 123, 'green' => 111, 'blue' => 55 }; */
See the SimpleDTO Project for more.
You can also export to different color formats:
$hexColor = $rgbSpeaker->toHexCode(); /** (string) $hexColor === #7B6F37 SimpleDTO => { 'hex' => '#7B6F37 } **/
All colors serializable and easily converted to JSON objects:
$linguist = ColorSpeaker::fromHexCode('#7B6F37'); $rgbColor = $linguist->toRGB(); echo json_encode($rgbColor, JSON_PRETTY_PRINT); /** { "red": 123, "green": 111, "blue": 55 } **/
Use cases
PHPExperts\ColorSpeaker\ColorSpeaker
✔ Can be constructed from an RGBColor
✔ Can be constructed from a HexColor
✔ Can be constructed from an HSLColor
✔ From RGB: Will only accept integers between 0 and 255, inclusive
✔ From CSS Hex: Will only accept a valid 3 or 6 digit Hex color string,
starting with a "#" sign
✔ Can return an RGBColor
✔ Can return a CSSHexColor
✔ Can return an HSLColor
✔ Can be outputted as a CSS string
PHPExperts\ColorSpeaker\DTOs\RGBColor
✔ Will only accept integers between 0 and 255, inclusive
✔ Will only accept literal integers
✔ Can be constructed with a zero-indexed array
✔ Can be outputted as a CSS string
PHPExperts\ColorSpeaker\DTOs\CSSHexColor
✔ Can assert if a string is a valid CSS hex color
✔ The hex code must start with a "#" sign
✔ Will only accept three digit and six digit hex codes
✔ Can be outputted as a CSS string
PHPExperts\ColorSpeaker\DTOs\HSLColor
✔ Will only accept a valid HSL geometry of percentages or percent-integers
✔ Can be constructed with a zero-indexed array
✔ Can be constructed with integers
✔ Can be outputted as a CSS string
Testing
phpunit --testdox
Contributors
Theodore R. Smith theodore@phpexperts.pro
GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
CEO: PHP Experts, Inc.
A big shoutout to https://www.w3schools.com/colors/colors_converter.asp. That wonderful color converter made this project's development 70% easier!
License
MIT license. Please see the license file for more information.
phpexperts/color-speaker 适用场景与选型建议
phpexperts/color-speaker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 06 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rgb colors」 「html colors」 「css colors」 「hex colors」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phpexperts/color-speaker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phpexperts/color-speaker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phpexperts/color-speaker 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Class that adds color to PHPUnit testing output using ANSI escape coding
A slick color picker fieldtype plugin for the Craft CMS 3 control panel.
Identify your matrix blocks by giving each type a different color.
The PHP Average Color Picker Library
Generates QR Codes
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-13