定制 10quality/php-css-color-parser 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

10quality/php-css-color-parser

最新稳定版本:v1.0.5

Composer 安装命令:

composer require 10quality/php-css-color-parser

包简介

Package used to parse CSS colors in order to normalize them into different formats.

README 文档

README

Latest Stable Version Total Downloads License

A little package used to parse CSS colors in order to normalize them into different formats (supported: hex, argb and rgba).

Requirements

  • PHP >= 5.4

Install

composer require 10quality/php-css-color-parser

Usage

Use statement:

use TenQuality\Utility\Color\CssParser;

For a normalized HEX code:

// This will echo "#44FCCD"
echo CssParser::hex('#44fCCd');

// This will echo "#44FFFF"
echo CssParser::hex('#4ff');

// This will echo "#FFFFFF"
echo CssParser::hex('white');

// This will echo "#89CC7F"
echo CssParser::hex('89cc7F');

For a normalized HEX code (with transparency):

// This will echo "#44FCCD44"
echo CssParser::hexTransparent('#44fCCd44');

// This will echo "#44FFFFFF"
echo CssParser::hexTransparent('#4ff');

// This will echo "#FFFFFFFF"
echo CssParser::hexTransparent('white');

For ARGB:

// This will echo "0x4444FCCD"
echo CssParser::argb('#44fCCd44');

// This will echo "0xFF44FFFF"
echo CssParser::argb('#4ff');

// This will echo "0xFFFFFFFF"
echo CssParser::argb('white');

For RGBA:

// This will echo "rgba(57,115,157,0.53)"
echo CssParser::rgba('#39739d88');

// This will echo "rgba(255,255,255,1)"
echo CssParser::rgba('white');

Casting

To return the color's rgba codes as an array:

// This will dump the following array "[57,115,157,255]"
var_dump(CssParser::array('#39739d'));

To return the color's rgba codes as a JSON string:

// This will echo "{"red":57,"green":115,"blue":157,"alpha":255}"
echo CssParser::string('#39739d');

Alpha

Default alpha can be changed from FF to 00 by calling to the following static method:

CssParser::setAlpha('0');
// Or
CssParser::setAlpha(CssParser::ALPHA_TRANSPARENT);

Resulting in:

// This will echo "#44FFFF00"
echo CssParser::hexTransparent('#4ff');

// This will echo "rgba(255,255,255,0)"
echo CssParser::rgba('white');

// This will echo "0x0044FFFF"
echo CssParser::argb('#4ff');

To restore the default alpha call:

CssParser::setAlpha('F');
// Or
CssParser::setAlpha(CssParser::ALPHA_OPAQUE);

Extending named colors

To add more CSS named colors:

// This will exho "#00008B"
echo CssParser::hex('darkblue', ['/darkblue/','/darkgreen/'], ['00008B','006400']);

NOTE: Second parameter passed by containes the list of additional css labels (names) to parse and the third paramener contains its HEX code in caps and without the hashtag character.

Copyright & License

MIT License.

(c) 2018 10 Quality

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-13