ivuorinen / palette
从图片中获取最常用的颜色
1.0.1
2013-07-01 13:03 UTC
Requires
- php: >=5.2.0
This package is auto-updated.
Last update: 2024-09-23 01:33:43 UTC
README
Palette 是一个 PHP 类,它接受您的图片,返回使用的颜色,按使用频率排序并将结果保存。
用法
在您的 composer.json
文件中添加 Palette 并安装到您的 vendor 文件夹后,您可以使用该类如下所示
使用默认设置
$image = "example/example.jpg"; $palette = new \ivuorinen\Palette\Palette($image); print_r($palette->colorsArray);
使用自定义设置
$palette = new \ivuorinen\Palette\Palette(); $palette->filename = "example/example.jpg"; // Our image $palette->precision = 10; // Precision of color collection $palette->returnColors = 10; // How many colors we want $palette->destination = './data/' . md5($palette->filename) . '.json'; // Do the work (same as ``Palette::run()``) $this->getPalette(); $this->save(); // Not needed, but caching results <3 // We now have ``./data/7233c3b944f5299c6983c77c94e75dce.json`` (if everything went smoothly) // and we can test against it before running palette generation. Which you should do really. print_r($palette->colorsArray);