konnco / laravel-color-thief
此包的最新版本(1.4.0)没有可用的许可证信息。
Laravel 对 `ksubileau/color-thief-php` 的包装。从图片中获取主色调或代表性调色板。使用 PHP 和 GD 或 Imagick。
1.4.0
2020-08-22 08:57 UTC
Requires
- php: >=5.6.4
- illuminate/support: ~5.5|^6.0|^7.0
- ksubileau/color-thief-php: ^1.3
This package is auto-updated.
Last update: 2024-09-22 18:31:06 UTC
README
Laravel 对 Color-Thief-PHP 的包装,增加了额外修改。从图片中获取 主色调 或 代表性调色板。使用 PHP 和 GD 或 Imagick。
此 Laravel 包非常实用,可以从图片中获取 主色调 或 代表性调色板。请参见此图像以获取示例。
内容
安装
您可以通过 Composer 安装此包
composer require nikkanetiya/laravel-color-palette
您必须安装服务提供者(对于 Laravel < 5.5)
// config/app.php 'providers' => [ ... NikKanetiya\LaravelColorPalette\ColorPaletteServiceProvider::class, ],
注册外观
// config/app.php 'aliases' => [ ... 'ColorPalette' => NikKanetiya\LaravelColorPalette\ColorPaletteFacade::class, ],
可用方法
-
getColor() - 使用此方法从图片中获取 最显著的单一颜色
示例
// get most dominant color from image $color = ColorPalette::getColor( 'https://rawcdn.githack.com/nikkanetiya/laravel-color-palette/master/tests/images/strawberry.jpeg' ); // Color provides several getters/properties echo $color; // '#dc5550' echo $color->rgbString; // 'rgb(220,85,80)' echo $color->rgbaString; // 'rgba(220,85,80,1)' echo $color->int; // 14439760 print_r($color->rgb); // array(220, 85, 80) print_r($color->rgba); // array(220, 85, 80, 1)
选项
$color = ColorPalette::getColor($sourceImage, $quality = 10, $area = null );
默认情况下,
getColor
将具有 quality -> 10 和 specific area -> null。Quality
可以是整数。1 是最高质量。质量和速度之间有一个权衡。数字越大,调色板生成速度越快,但颜色丢失的可能性也越大。Area
可以是数组|null $area[x,y,w,h]。它允许您指定图像中的矩形区域,以便仅获取此区域的颜色。它需要是一个关联数组,具有以下键- $area['x']: 区域左上角的 x 坐标。默认为 0。
- $area['y']: 区域左上角的 y 坐标。默认为 0。
- $area['w']: 区域的宽度。默认为从 x 坐标减去图像宽度。
- $area['h']: 区域的高度。默认为从 y 坐标减去图像高度。
-
getPalette() - 使用此方法从图片中找到 代表性调色板
示例
// get colors from image $colors = ColorPalette::getPalette( 'https://github.com/nikkanetiya/laravel-color-palette/blob/master/tests/images/strawberry.jpeg' ); foreach($colors as $color) { // } // Colors will be array of Color Objects
选项
$color = ColorPalette::getPalette($sourceImage, $colorCount = 10, $quality = 10, $area = null)
colorCount
可以是 2 到 256。这是您要为图片获取的颜色数量。Quality
和Area
与上面相同。
图片来源: https://www.pexels.com
, google image