mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
Remove color gradient
This commit is contained in:
parent
ad296d4b04
commit
420a824665
|
|
@ -27,47 +27,6 @@ namespace phpOMS\Utils;
|
|||
class ColorUtils
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a 3 point gradient based on a input value.
|
||||
*
|
||||
* @param int $value Value to represent by color
|
||||
* @param int[] $start Gradient start
|
||||
* @param int[] $stop Gradient stop
|
||||
* @param int[] $end Gradient end
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function getRGBGradient(int $value, array $start, array $stop, array $end) : array
|
||||
{
|
||||
$diff = [];
|
||||
$gradient = [];
|
||||
|
||||
if ($value <= $stop[0] && $value < $start[0]) {
|
||||
$value = $start[0];
|
||||
} else {
|
||||
$value = min($value, $end[0]);
|
||||
$start = $stop;
|
||||
$stop = $end;
|
||||
}
|
||||
|
||||
$diff[0] = $stop[0] - $start[0];
|
||||
$diff[1] = $stop[1] - $start[1];
|
||||
$diff[2] = $stop[2] - $start[2];
|
||||
$diff[3] = $stop[3] - $start[3];
|
||||
|
||||
$gradient['r'] = $start[1] + ($value - $start[0]) / ($diff[0]) * $diff[1];
|
||||
$gradient['g'] = $start[2] + ($value - $start[0]) / ($diff[0]) * $diff[2];
|
||||
$gradient['b'] = $start[3] + ($value - $start[0]) / ($diff[0]) * $diff[3];
|
||||
|
||||
foreach ($gradient as &$color) {
|
||||
$color = max(min($color, 255), 0);
|
||||
}
|
||||
|
||||
return $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert int to rgb
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user