aryehraber/statamic-color-extractor
Composer 安装命令:
composer require aryehraber/statamic-color-extractor
包简介
Extract colors from images.
README 文档
README
Extract colors from images.
This addon provides a new Modifier which takes an image asset and returns its dominant (or average) color as a HEX value.
Installation
Install the addon via composer:
composer require aryehraber/statamic-color-extractor
Publish the config file:
php artisan vendor:publish --tag=color_extractor-config
Usage
Simply add the color modifier to an image asset to output the HEX color value:
{{ image | color }}
Example
--- image: my-colorful-image.jpg --- <div style="border-color: {{ image | color }};"> <img src="{{ image }}" /> </div> // OR {{ image }} <div style="border-color: {{ url | color }};"> <img src="{{ glide:id }}" /> </div> {{ /image }}
By default, the underlying color extractor tries to find the most dominant color in the image, however, results can vary (see example screenshot below). Therefore, an average param can be passed in to instead find the average color found in the image:
{{ image | color:average }}
The default type can be changed to average instead via the config file, which opens up a dominant param:
{{ image | color:dominant }}
The contrast parameter will try to find a color from the image palette with the most contrast to the dominant color:
{{ image | color:contrast }}
Dominant vs. Average vs. Contrast
Example screenshot to demonstrate the difference between the color extraction strategies:
Manually Editing Colors
Whenever a color is extracted from an image, it's added to the asset's meta data. This means you can manually override it by adding the following fields to your assets.yaml blueprint:
title: Asset fields: # existing fields - handle: color_dominant field: display: Dominant Color type: color - handle: color_average field: display: Average Color type: color - handle: color_contrast field: display: Contrast Color type: color
Extract Command
By default, colors are extracted on-demand when the modifier is first used on an image. This can slow down page loads with many images.
To improve performance, pre-generate color data using the commands below.
Note: The command will skip assets that already have color data unless --force is used.
# Extract default color type for all assets php please color-extractor:extract # Extract all color types (dominant, average, contrast) php please color-extractor:extract --all # Filter by container php please color-extractor:extract --container=assets # Filter by container and folder php please color-extractor:extract --container=assets --folder=products # Force re-extraction even if colors already exist php please color-extractor:extract --force
Auto Extract on Asset Upload
When auto_extract is enabled in the config file (see Installation), colors will automatically be extracted when new images are uploaded. This extracts all 3 color types (dominant, average, contrast) and is useful to ensure there's no slow down on first page load.
Credits
Inspiration: https://github.com/sylvainjule/kirby-colorextractor
Color Extractor: https://github.com/thephpleague/color-extractor
aryehraber/statamic-color-extractor 适用场景与选型建议
aryehraber/statamic-color-extractor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.67k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2020 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「statamic」 「color extractor」 「image color」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aryehraber/statamic-color-extractor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aryehraber/statamic-color-extractor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aryehraber/statamic-color-extractor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A simple library that uses the hydration pattern to fill objects given different sources of data.
Native (browser) color input field for SilverStripe
Colorizes the Flarum forum header and interface based on the active tag's color.
Statamic Fine Seo addon
Bing Image Extractor
统计信息
- 总下载量: 8.67k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-20

