skyree/php-colorpicker
Composer 安装命令:
composer require skyree/php-colorpicker
包简介
Pick a palette of dominant colors within an image
README 文档
README
Pick a palette of dominant colors from an image
Requirements
- php 7.1
- ext-imagick
Installation
Clone or download the repository and simply run composer install
Demo
In order to use the demo, run the following command
cd demo
php -S localhost:8000
And open the url localhost:8000 in your browser
Getting started
Use the Lol\ColorPicker\ColorPicker class in your file
Example of usage:
$imageUrl = 'http://some.website/some/image.ext'; $colorPicker = new ColorPicker(); $palette = $colorPicker->pick($imageUrl, ColorPicker::KMEANS, 7, 150); foreach ($palette as $cluster) { echo sprintf("#%02x%02x%02x", ...$cluster['color']) . PHP_EOL; // will print up to 5 hex codes }
Options
ColorPicker::pick($imageUrl, $algorithm, $paletteSize, $resize);
$imageUrlis the url of the image you want to pick colors from$algorithmis the algorithm to use amongColorPicker::KMEANS,ColorPicker::WEIGHTED_KMEANS,ColorPicker::LOCAL_MAXIMA$paletteSizeis the maximum quantity of dominant colors you want to pick$resizeis the width to which the image should be resized, it can be left empty$quantizationis an array providing the colorspace and number of colors for the quantization, formatted as follow:
$quantization = [ 'colorNumber' => 64, 'colorSpace' => 1 // RGB space ];
Algorithms
ColorPicker::KMEANSuses a standard unsupervised Kmeans or Kmeans++ algorithm to calculate k clusters, some clusters can end up emptyColorPicker::WEIGHTED_KMEANSimplementation of Kmeans from an histogram, calculating the clusters centroids according to coordinate and weightColorPicker::LOCAL_MAXIMAkeeps the maximum values among their 27 neighboring cells in a 3d space of quantized rgb values. Incompatible with quantization argument !ColorPicker::QUANTIZATIONjust quantize the colors and return the highest clusters
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-17