villfa/invert-color
Composer 安装命令:
composer require villfa/invert-color
包简介
InvertColor - invert hex color code
README 文档
README
invert hex color code
Installation
composer require villfa/invert-color
Usage
Here a basic example:
<?php require_once 'vendor/autoload.php'; use InvertColor\Color; use InvertColor\Exceptions\InvalidColorFormatException; try { echo Color::fromHex('#fff')->invert(); // #000000 } catch (InvalidColorFormatException $e) { echo 'Invalid color: ', $e->getValue(); }
Color::fromHex(string $color): Color - throws InvalidColorFormatException
$color:stringColor in HEX string. Accepted formats: #000000, #000, 000000, 000
InvertColor\Color::fromHex('#fff')->invert(); // #000000
Color::fromRGB(array $rgb): Color - throws InvalidRGBException
$rgb:arrayColor as an array of RGB values.
InvertColor\Color::fromRGB([0, 255, 0])->invert(); // #ff00ff
Color::invert([bool $bw]): string
$bw:boolOptional. A boolean value indicating whether the output should be amplified to black (#000000) or white (#ffffff), according to the luminance of the original color.
InvertColor\Color::fromHex('#000')->invert(); // #ffffff InvertColor\Color::fromHex('#282b35')->invert(); // #d7d4ca // amplify to black or white InvertColor\Color::fromHex('282b35')->invert(true); // #ffffff
Color::invertAsRGB([bool $bw]): array
$bw:boolOptional. A boolean value indicating whether the output should be amplified to black or white, according to the luminance of the original color.
InvertColor\Color::fromHex('#000')->invertAsRGB(); // [255, 255, 255] InvertColor\Color::fromHex('#282b35')->invertAsRGB(); // [215, 212, 202] // amplify to black or white InvertColor\Color::fromHex('282b35')->invertAsRGB(true); // [255, 255, 255]
Color::invertAsObj([bool $bw]): Color
$bw:boolOptional. A boolean value indicating whether the output should be amplified to black or white, according to the luminance of the original color.
InvertColor\Color::fromHex('#000')->invertAsObj()->getHex(); // #ffffff InvertColor\Color::fromHex('#282b35')->invertAsObj()->getRGB(); // [215, 212, 202] // amplify to black or white InvertColor\Color::fromHex('282b35')->invertAsObj(true)->getRGB(); // [255, 255, 255]
Color::getHex(): string
InvertColor\Color::fromHex('#FFF')->getHex(); // #ffffff
Color::getRGB(): array
InvertColor\Color::fromHex('#fff')->getRGB(); // [255, 255, 255]
Color::getLuminance(): float
InvertColor\Color::fromHex('#fff')->getLuminance(); // 1 InvertColor\Color::fromHex('#000')->getLuminance(); // 0
Color::isBright(): bool
InvertColor\Color::fromHex('#fff')->isBright(); // true InvertColor\Color::fromHex('#000')->isBright(); // false
Color::isDark(): bool
InvertColor\Color::fromHex('#fff')->isDark(); // false InvertColor\Color::fromHex('#000')->isDark(); // true
Tests
To validate and test the library:
composer run-script test
Acknowledgement
This library is a port of the JS package invert-color.
More resources:
- https://stackoverflow.com/questions/35969656/how-can-i-generate-the-opposite-color-according-to-current-color
- https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color/3943023#3943023
License
villfa/invert-color 适用场景与选型建议
villfa/invert-color 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 125.5k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2017 年 10 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「color」 「colour」 「reverse」 「Inverse」 「invert」 「opposite」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 villfa/invert-color 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 villfa/invert-color 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 villfa/invert-color 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Prominent image colour extraction for PHP
A slick color picker fieldtype plugin for the Craft CMS 3 control panel.
Native (browser) color input field for SilverStripe
The TYPO3 Cloudflare Extension simplifies cache management, offering an efficient solution for TYPO3 administrators and developers. Seamlessly integrating with Cloudflare, a global leader in web performance and security, this extension provides advanced features to optimize, secure, and structure yo
a one to one and one to many reverse relation for laravel
Nominatim Geocoding API Client
统计信息
- 总下载量: 125.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 22
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-11