PHPackages                             zhb/weather-gradient - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. zhb/weather-gradient

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

zhb/weather-gradient
====================

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

v0.2.0(4y ago)27351MITPHPPHP ^7.4 || ^8.0 || ^8.1

Since Jul 24Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ZHB/weather-gradient)[ Packagist](https://packagist.org/packages/zhb/weather-gradient)[ RSS](/packages/zhb-weather-gradient/feed)WikiDiscussions Develop Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (4)Used By (0)

Weather Gradient
================

[](#weather-gradient)

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](https://github.com/ZHB/weather-gradient/actions/workflows/tests.yaml/badge.svg)](https://github.com/ZHB/weather-gradient/actions/workflows/tests.yaml) [![codecov](https://camo.githubusercontent.com/a2acb603d8f469b813e02d05df8d680ef4bec218ef1d7e19ad206608205001f6/68747470733a2f2f636f6465636f762e696f2f67682f5a48422f776561746865722d6772616469656e742f6272616e63682f446576656c6f702f67726170682f62616467652e7376673f746f6b656e3d54463430575658324e4c)](https://codecov.io/gh/ZHB/weather-gradient)

 [![](./doc/temperature-gradient.png "Weather Gradient example")](./doc/temperature-gradient.png)

Documentation
-------------

[](#documentation)

### Installation

[](#installation)

Use [Composer](http://getcomposer.org/) to install Weather Gradient in your project :

```
composer require "zhb/weather-gradient"
```

### Usage

[](#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

[](#examples)

A usage example can be found in [example](./example) folder.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~84 days

Total

2

Last Release

1675d ago

PHP version history (2 changes)v0.1.0PHP ^7.4 || ^8.0

v0.2.0PHP ^7.4 || ^8.0 || ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/108f43962efa3a9170a28125da69dff8f992059ec43aa063cf90cb6fc880ec05?d=identicon)[ZHB](/maintainers/ZHB)

---

Top Contributors

[![ZHB](https://avatars.githubusercontent.com/u/219280?v=4)](https://github.com/ZHB "ZHB (11 commits)")[![apiaget](https://avatars.githubusercontent.com/u/634083?v=4)](https://github.com/apiaget "apiaget (1 commits)")

---

Tags

weathergradientcolors

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zhb-weather-gradient/health.svg)

```
[![Health](https://phpackages.com/badges/zhb-weather-gradient/health.svg)](https://phpackages.com/packages/zhb-weather-gradient)
```

###  Alternatives

[tomloprod/colority

Colority is a lightweight PHP library designed to handle color transformations, validations and manipulations with ease.

22688.4k1](/packages/tomloprod-colority)[tecnickcom/tc-lib-color

PHP library to manipulate various color representations

247.2M9](/packages/tecnickcom-tc-lib-color)[doublesecretagency/craft-matrixcolors

Identify your matrix blocks by giving each type a different color.

4518.3k](/packages/doublesecretagency-craft-matrixcolors)[presseddigital/colorit

A slick color picker fieldtype plugin for the Craft CMS 3 control panel.

2132.1k](/packages/presseddigital-colorit)[amwhalen/noaa

Client library for NOAA's forecast and current weather services

301.5k](/packages/amwhalen-noaa)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
