An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

Colorizer
=========


Colorizer


Join our Community
Become a Sponsor
One-time Donation


Latest Stable Version
Total Downloads
License
Build Status


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).