yarri/material-palette
最新稳定版本:1.3.0
Composer 安装命令:
composer require yarri/material-palette
包简介
Prominent image colour extraction for PHP
README 文档
README
Palette is a port of the Android library of the same name, for extracting a colour palette from an image. The results can then be used for tinting the interface to match the image.
Installation
$ composer require 'marijnvdwerf/material-palette:~1.0'
Usage
Palette makes use of the Intervention image library to load images, and supports both the Imagick and GD drivers. The performance of the Imagick driver is slightly better, but the difference is fairly small.
$manager = new ImageManager(array('driver' => 'imagick')); $image = $manager->make('path/to/image.png'); $palette = Palette::generate($image); echo $palette->getVibrantSwatch()->getColor();
Contrast
You can get the contrast of a colour on a non-translucent background by calling
AbstractColor::calculateContrast($background, $foreground). Information on the recommended contrast ratio can be found
at the W3C recommendation.
$white = new RGBColor(1, 1, 1); $black = new RGBColor(0, 0, 0); $background = $palette->getVibrantSwatch()->getColor(); echo '<div style="background: ' . $background . '">'; if(AbstractColor::calculateContrast($background, $white) >= 3) { echo '<h1 style="color: white;">Palette</h1>'; } else { echo '<h1 style="color: black;">Palette</h1>'; } echo '</div>';
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2025-09-22
