定制 skyree/php-colorpicker 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  • $imageUrl is the url of the image you want to pick colors from
  • $algorithm is the algorithm to use among ColorPicker::KMEANS, ColorPicker::WEIGHTED_KMEANS, ColorPicker::LOCAL_MAXIMA
  • $paletteSize is the maximum quantity of dominant colors you want to pick
  • $resize is the width to which the image should be resized, it can be left empty
  • $quantization is an array providing the colorspace and number of colors for the quantization, formatted as follow:
$quantization = [
    'colorNumber' => 64,
    'colorSpace' => 1 // RGB space
];

Algorithms

  • ColorPicker::KMEANS uses a standard unsupervised Kmeans or Kmeans++ algorithm to calculate k clusters, some clusters can end up empty
  • ColorPicker::WEIGHTED_KMEANS implementation of Kmeans from an histogram, calculating the clusters centroids according to coordinate and weight
  • ColorPicker::LOCAL_MAXIMA keeps the maximum values among their 27 neighboring cells in a 3d space of quantized rgb values. Incompatible with quantization argument !
  • ColorPicker::QUANTIZATION just quantize the colors and return the highest clusters

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-04-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固