定制 zhb/weather-gradient 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zhb/weather-gradient

Composer 安装命令:

composer require zhb/weather-gradient

包简介

Library for determining the color at a specific position in a bounded color gradient.

README 文档

README

Weather gradient is a small library allowing to determine the RGB color at a given value in an interval bounded by a combination of a minimum value and a color and a combination of a maximum value and a color.

In addition to the minimum and maximum limits, it is possible to add as many thresholds as desired.

Test codecov

Documentation

Installation

Use Composer to install Weather Gradient in your project :

composer require "zhb/weather-gradient"

Usage

$colors =  [
    0 => [59, 130, 246], // blue
    30 => [239, 68, 68], // red
];

// create a gradient from given thresholds
$gradient = Gradient::fromColors($colors);

// get the RGB color at a specific gradient position
$color = $gradient->colorAtGradientPosition(18);

// print the color
echo $color; // rgb(167, 92, 139)

// or get r, g, b values
$r = $color->getR();
$g = $color->getG();
$b = $color->getB();

In addition to the Gradient class, you can use the Contrast::darkOrLight(array $rgb) to determine if a dark or light text fit the best with the given rgb color.

// $bestColor will contain [255, 255, 255] (white)
$bestColor = Contrast::darkOrLight($darkBlue = [85, 101, 242]);

// $bestColor will contain [0, 0, 0] (black)
$bestColor = Contrast::darkOrLight($lightBlue = [59, 130, 246]);

Examples

A usage example can be found in example folder.

统计信息

  • 总下载量: 829
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固