brianmcdo/image-palette
Composer 安装命令:
composer require brianmcdo/image-palette
包简介
Extracts colors from an image and generates a color palette against a whitelist of colors.
README 文档
README
ImagePalette is used to extract a color palette from a given image. Aside from being a native PHP implementation, ImagePalette differs from many palette extractors as it works off a white list color palette. Below is the default palette:
The main advantage of working from a color palette is closer matching, as each pixel simply has to calculate the color-distance within the palette and chose the best match. This is useful for working with color taxonomies as the taxonomy should have a finite amount of colors.
See an example of this in action here: http://alpha.wallhaven.cc/wallpaper/21852
Requirements
PHP >= 5.4 php5-gd
Installation
Simply add the following to your composer.json file:
"require": { "brianmcdo/image-palette": "dev-master" }
Usage
// initiate with image $palette = new \BrianMcdo\ImagePalette\ImagePalette( 'https://www.google.co.uk/images/srpr/logo3w.png' ); // get the prominent colors $colors = $palette->colors; // array of Color objects // to string as json echo $palette; // '["#ffffdd", ... ]' // implements IteratorAggregate foreach ($palette as $color) { // Color provides several getters/properties echo $color; // '#ffffdd' echo $color->rgbString; // 'rgb(255,255,221)' echo $color->rgbaString; // 'rgba(255,255,221,0.25)' echo $color->int; // 0xffffdd echo $color->rgb; // array(255,255,221) echo $color->rgba; // array(255,255,221,0.25) // ... }
And there we go!
Laravel 4
Find the providers key in app/config/app.php and register the ImagePaletteServiceProvider:
'providers' => array( // ... 'BrianMcdo\ImagePalette\Laravel\ImagePaletteServiceProvider', )
Then, find the aliases key in app/config/app.php and register the ImagePaletteFacade:
'aliases' => array( // ... 'ImagePalette' => 'BrianMcdo\ImagePalette\Laravel\ImagePaletteFacade', )
Example:
$fileOrUrl = 'https://www.google.com/images/srpr/logo11w.png'; ImagePalette::getColors($fileOrUrl);
Options
Precision
By default, ImagePalette will process every 10th pixel. This is for performance reasons, you can change this like below. The precision is a performance-to-time decision.
$palette = new \BrianMcdo\ImagePalette\ImagePalette( $src, 5 /* precision */ );
Color Count
To control the amount colors returned set the third parameter. You can also provide the getter with a custom length.
$palette = new \BrianMcdo\ImagePalette\ImagePalette( $src, 5, 3 /* number of colors to return */ ); $colors = $palette->getColors(7 /* number of colors to return */);
Contribution guidelines
See: https://github.com/brianmcdo/ImagePalette/blob/master/CONTRIBUTING.md
brianmcdo/image-palette 适用场景与选型建议
brianmcdo/image-palette 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 221.59k 次下载、GitHub Stars 达 179, 最近一次更新时间为 2014 年 10 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「color」 「gd」 「laravel」 「extractor」 「palette」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 brianmcdo/image-palette 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 brianmcdo/image-palette 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 brianmcdo/image-palette 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
Native (browser) color input field for SilverStripe
Colorizes the Flarum forum header and interface based on the active tag's color.
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
Color conversion library
统计信息
- 总下载量: 221.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 183
- 点击次数: 32
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-10-04