https://github.com/phlak/colorizer
PHP library for generating persistantly unique colors from a string.
https://github.com/phlak/colorizer
color persistent-colors php
Last synced: 10 months ago
JSON representation
PHP library for generating persistantly unique colors from a string.
- Host: GitHub
- URL: https://github.com/phlak/colorizer
- Owner: PHLAK
- License: mit
- Created: 2014-04-08T04:00:44.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2024-12-06T18:53:58.000Z (over 1 year ago)
- Last Synced: 2024-12-06T20:58:22.586Z (over 1 year ago)
- Topics: color, persistent-colors, php
- Language: PHP
- Size: 130 KB
- Stars: 12
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Colorizer
=========
Generate persistently unique colors from a string.
Created by Chris Kankiewicz (@PHLAK)
---
Requirements
------------
- [PHP](https://php.net) >= 8.1
Install with Composer
---------------------
```bash
composer require phlak/colorizer
```
Usage
-----
```php
// Import Colorizer
use PHLAK\Colorizer;
// Initialize Colorizer
$colorize = new Colorizer\Colorize();
// Generate a Color object from 'foo'
$color = $colorize->text('foo'); // Returns a new Color object
// Get the red, green and blue values
$color->red; // 165
$color->green; // 196
$color->blue; // 254
// Generate a hex color code
$color->hex(); // Returns '#a5c4fe'
// Generate a RGB color code
$color->rgb(); // Returns 'rgb(165, 196, 254)'
```
#### Normalizing Colors
You can enforce RGB values to fall within a certain range to prevent colors
from being too bright or dark. This is possible by passing minimum and maximum
normalization values (0-255) to the Colorize class on initialization:
```php
$colorize = new Colorizer\Colorize(64, 224);
```
or fluently:
```php
$colorize->text('foo')->normalize(64, 224)->rgb(); // Returns 'rgb(165, 196, 224)'
```
Changelog
---------
A list of changes can be found on the [GitHub Releases](https://github.com/PHLAK/Colorizer/releases) page.
Troubleshooting
---------------
For general help and support join our [GitHub Discussion](https://github.com/PHLAK/Colorizer/discussions)
or reach out on [Bluesky](https://bsky.app/profile/phlak.dev).
Please report bugs to the [GitHub Issue Tracker](https://github.com/PHLAK/Colorizer/issues).
Copyright
---------
This project is licensed under the [MIT License](https://github.com/PHLAK/Colorizer/blob/master/LICENSE).