diff --git a/src/Color.php b/src/Color.php index 78e8fae..ac681cb 100644 --- a/src/Color.php +++ b/src/Color.php @@ -70,9 +70,9 @@ public function initFromArray($value) $alpha = $this->alpha2vips($array[2]); } - $this->red = (int) $red; - $this->green = (int) $green; - $this->blue = (int) $blue; + $this->red = $this->clampValue($red); + $this->green = $this->clampValue($green); + $this->blue = $this->clampValue($blue); $this->alpha = $alpha; } @@ -221,4 +221,14 @@ protected function alpha2vips($input): int return (int) ceil($input * 255); } + + /** + * @param $value + * + * @return int + */ + protected function clampValue($value): int + { + return (int) min(255, $value); + } }