wwaz/colormodel-php 问题修复 & 功能扩展

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

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

wwaz/colormodel-php

最新稳定版本:v1.0.3

Composer 安装命令:

composer require wwaz/colormodel-php

包简介

Basic color models and conversions

README 文档

README

Convert, manipulate, and generate color schemes across all major color spaces — with a clean, chainable PHP API.

composer require wwaz/colormodel-php

What it does

  • 10 color models — HEX, RGB, RGBA, HSB, HSV, HSL, CMYK, CMYKInt, CIELab, CIELCh, XYZ
  • Fluent conversions — chain from one color space to another in a single expression
  • Color manipulation — rotate hue, mix colors with custom weights
  • Color schemes — Complementary, Triadic, Tetradic, Square, Analogous, Tint, Tone, Shade
  • Flexible input/output — accept strings, arrays, integers, or named colors like 'red'

Examples

1. Cross-Format Conversion Chain

Start with a HEX color, rotate its hue by 180°, and export as CMYK — perfect for generating print-ready complementary colors from web values:

use wwaz\Colormodel\Model\Hex;

$cmyk = (new Hex('#f00'))
    ->hue(180)
    ->toCMYK();

echo $cmyk->toString();    // 100,0,0,0
echo $cmyk->toHtml();      // cmyk(100,0,0,0)
echo $cmyk->toArray();     // [100, 0, 0, 0]

2. Mixing Colors with Custom Weight

Blend two colors in any ratio. Great for generating palette gradients or brand color variations programmatically:

use wwaz\Colormodel\Model\Hex;

$red  = new Hex('#ff0000');
$blue = new Hex('#0000ff');

// 50/50 mix → purple
echo $red->mix($blue)->toString();        // 800080

// 75/25 mix (more red) → darker pink
echo $red->mix($blue, 0.25)->toString();  // BF0040

3. Generate a Full Color Scheme

Feed in any color, get back a complete set of harmonious variations — all returned in the same color model you started with:

use wwaz\Colormodel\Model\RGB;
use wwaz\Colormodel\Scheme\Complementary;
use wwaz\Colormodel\Scheme\Triadic;
use wwaz\Colormodel\Scheme\Analogous;
use wwaz\Colormodel\Scheme\Tint;

$base = new RGB(255, 0, 0); // red

(new Complementary($base))->get(); // ['255,0,0', '0,255,255']
(new Triadic($base))->get();       // red + 2 harmonics
(new Analogous($base))->get();     // neighboring hues
(new Tint($base))->get();          // lighter variations

// Works with CMYK too — output stays in CMYK
use wwaz\Colormodel\Model\CMYKInt;
$cyan = new CMYKInt(100, 0, 0, 0);
(new Complementary($cyan))->get(); // ['100,0,0,0', '0,100,100,0']

Color Models

Model Channels Typical use
HEX #RRGGBB HTML / CSS
RGB 0–255 per channel Screen / digital
RGBA RGB + alpha (0–1) CSS with transparency
HSB/HSV Hue 0–360°, Sat 0–100, Bri 0–100 Color pickers
HSL Hue 0–360°, Sat 0–100, Lig 0–100 CSS / design tools
CMYK 0–1 float per channel Print (float)
CMYKInt 0–100 int per channel Print (integer)
CIELab L 0–100, a, b axes Perceptual color science
CIELCh L, Chroma, Hue Smooth color gradients
XYZ Device-independent reference Color math / ICC

Development

Setup

composer install

Quality checks

composer check

You can also run the checks individually:

composer test
composer analyse
composer lint

Backward compatibility policy

  • Existing public APIs are kept backward-compatible.
  • Legacy usage with new HEX(...) remains supported.
  • New APIs are added in an additive way to avoid breaking existing integrations.

Contributing

Please see CONTRIBUTING.md for development workflow and pull request expectations.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固