10quality/php-css-color-parser 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱: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.7k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固