venca-x/latte-contrast-yiq

Nette 插件。默认用法是用于 Latte 模板。从 RGB 颜色返回对比颜色黑色/白色

dev-master 2018-01-05 11:15 UTC

This package is auto-updated.

Last update: 2024-09-07 05:02:48 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Nette 插件。默认用法是用于 Latte 模板。从 RGB 颜色返回对比颜色黑色/白色。通常用于设置对比文本颜色以适应动态颜色背景。

安装

  1. 将包添加到您的依赖中

使用 composer 安装

	composer require venca-x/latte-contrast-yiq:~0.2
	
	
// composer.json

    {
       // ...
       "require": {
           // ...
		   "venca-x/latte-contrast-yiq": "@dev",
       }
    }
  1. 使用 Composer 下载并安装包

    composer update
    

配置

BasePresenter.php

protected function beforeRender()
{
    parent::beforeRender();

    $this->template->addFilter('contrastYIQ', function ($text) {
        $contrastYIQ = new \ContrastYIQ();
        return $contrastYIQ->getContrastYIQ($text);
    });
}

用法

{$o->color|contrastYIQ}