https://github.com/fredtux/photocolornames
Heterogeneous libraries integrator for image color extraction and naming
https://github.com/fredtux/photocolornames
color-extraction color-namer composer image-analysis packagist php-color-extraction php-color-name php-color-namer php-image php-library
Last synced: 4 months ago
JSON representation
Heterogeneous libraries integrator for image color extraction and naming
- Host: GitHub
- URL: https://github.com/fredtux/photocolornames
- Owner: fredtux
- License: mit
- Created: 2017-07-10T21:38:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-08-26T20:46:17.000Z (over 5 years ago)
- Last Synced: 2025-06-23T21:02:25.427Z (9 months ago)
- Topics: color-extraction, color-namer, composer, image-analysis, packagist, php-color-extraction, php-color-name, php-color-namer, php-image, php-library
- Language: PHP
- Size: 52.7 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PhotoColorNames
**Heterogeneous libraries integrator for image color extraction and naming**
## Usage
A simple example with comments
```php
setDefaultOptions();
// Name the colors
/// Use the factory to retrieve a new object for color naming
$nameGiver = ColorNamesFactory::getColorNameGiver('ntc');
/// Use a list of names
$nameList = NamePool::getNtcNames();
// Construct object using the 4 variables declared before
$nameColor = new NameColor($photoColors, $photoColorOptions, $nameGiver, $nameList);
// Use the newly created object to get the names of the most frequently used colors in the file
$x = $nameColor->getNamesOfFrequentlyUsedColors();
### END OF MAIN ###
// Print result (not part of MAIN because it's not necessary)
print_r($x);
```
## Adding new libraries
### By Source
#### Composer
Just add it to composer.json and install. Composer will integrate it easily into the project.
[Packagist project](https://packagist.org/packages/fredtux/photo-color-names)
#### Non-composer
It is recommended, though not enforced, to place it into the **NoComposer** folder under the **ColorNames** or **PhotoColors** folders depending on the purpose of the new library.
### By Type
#### Color Extractors
##### Libraries
1. An adapter must be created in src/PhotoColors/Adapters
2. The adapter must implement iPhotoColorExtractor
- has a function called **getColors**
- has 1 parameter
- **$photoColorExtractorOptions** of type **PhotoColorExtractorOptions**
- implements all the logic necessary to issue the same type of results like the examples from 5 (no return type enforced since it's designed to run on PHP >= 5.6)
3. The action of constructing an object of the adapter's type must be placed in a new case under the switch from the method **getColorExtractor** from **PhotoColorFactory**
4. The new library can be used by creating an object from the factory
```php
PhotoColorFactory::getColorExtractor('ColorExtractorLibrary');
```
5. Examples
- PhotoColorNames\PhotoColors\Adapters\ColorThiefAdapter
- GetMostCommonColorsAdapter
#### Extractor options
New extractor options classes can be specified, but have to be paired with the color extractor class
1
#### Color Names
##### Libraries
1. An adapter must be created in src/ColorNames/Adapters
2. The adapter must implement iPhotoColorNamesGiver
- has a function called **getName**
- has 2 parameters
- **$colorName** of type **ColorData**
- **$nameList** of type **array**
- implements all the logic necessary to issue the same type of results like the example from 5 (no return type enforced since it's designed to run on PHP >= 5.6)
3. The action of constructing an object of the adapter's type must be placed in a new case under the switch from the method **getColorNameGiver** from **ColorNamesFactory**
4. The new library can be used by creating an object from the factory
```php
ColorNamesFactory::getColorNameGiver('ColorNamingLibrary');
```
5. Examples
- PhotoColorNames\ColorNames\Adapters\NtcAdapter
##### Name lists
It is recommended, though not enforced, to add new name lists to **NamePool** as a static method that returns an array which has the key as the color's RGB hex code and the value as an array containing the name
## License
This project is released under MIT license.
In this project there are algorithms from various sources. I do my best to respect the code license and give credit to the owner, but if you think your license has been breached, please feel free to open an issue and I'll solve it as soon as possible.