承接 phpexperts/color-speaker 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phpexperts/color-speaker

Composer 安装命令:

composer require phpexperts/color-speaker

包简介

An easy-to-use converter for different types of color models.

README 文档

README

Travis CIMaintainability Maintainability Test Coverage

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.

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-06-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固