mgamadeus / colorist
一个用于颜色管理和生成Material Design调色板的PHP工具包。包含一系列用于颜色表示和转换的类,使鲜艳的颜色方案和自定义调色板能够无缝集成到Web和应用程序项目中,精确提升您的设计。
1.1.4
2024-08-21 13:48 UTC
Requires
- php: >=8.1
README
Colorist 是一个PHP库,用于在多种颜色空间之间进行高级操作和转换,以及生成Material Design色调。
关键特性
- 多种颜色空间:支持RGB、HSL、XYZ、LAB和LCH等多种颜色空间,满足广泛的颜色操作和转换需求。
- 无缝互操作性:支持颜色空间之间的精确和简便转换,使复杂的颜色操作和分析能够满足特定需求。
- 受Material Design启发的调色板和色调:利用LCH和HSL颜色空间生成和谐且视觉上吸引人的调色板和色调,利用Material Design指南中的逻辑。此功能特别有利于UI/UX设计、品牌建设、主题应用以及实现所需的颜色渐变。* 注意 *:该包使用与Material Design相同的色调生成算法,但生成的色调在颜色代码上可能有所不同,但视觉上几乎不可察觉。原因是material design JS最初将颜色从RGB转换到另一个颜色空间,然后再转换回来,没有任何原因,并由此产生不准确,而Colorist没有这种不准确。
- 可定制和可扩展:易于扩展以包含额外的颜色空间和转换方法,确保库能够适应不断发展的项目需求以及颜色科学的进步。
使用Colorist
颜色类概述
在 Colorist 中,每个颜色空间都由一个专用类表示,配备有转换、操作和分析的方法。以下是简要概述
RgbColor
:表示RGB颜色空间中的颜色,提供转换到其他空间和生成十六进制颜色代码的方法。HslColor
:处理HSL颜色空间中的颜色,允许对色调、饱和度和亮度进行直观调整。XyzColor
和LabColor
:在XYZ和LAB颜色空间中工作,对于颜色科学和精确颜色匹配至关重要。LchColor
:对于生成自定义调色板至关重要,该类表示LCH颜色空间,并提供受Material Design启发的调色板创建方法。
从RGB颜色生成调色板
Colorist简化了从单个基色创建和谐调色板的过程,借鉴了Material Design原则以确保一致性和审美。以下是直接从表示为十六进制格式的RGB颜色生成调色板的方法
use Colorist\ColorSpaces\RgbColor; // Create an RGB color from a hexadecimal code $rgbColor = RgbColor::fromHex('#3498db'); // Directly generate Shades based on the RGB color $shades = $rgbColor->createShades(); // Display the hexadecimal codes of the generated palette colors foreach ($shades->getShades() as $shade) { echo $shade->getColor()->getRgbHex() . PHP_EOL; } This example demonstrates the library's capability to not only produce cohesive palettes but also specific shades that adhere to the Material Design guidelines, enhancing the versatility in color manipulation for your projects. --- **Colorist** is here to simplify color manipulation and help you achieve the perfect palette for your projects, backed by the sound principles of color science and Material Design. Whether you're developing a website, creating digital art, or designing a user interface, **Colorist** offers the tools you need to work with colors more effectively and creatively.