Skip to content

Commit

Permalink
Clamp RGB values
Browse files Browse the repository at this point in the history
When brightening an image, color values from getpoint() can be over 255
  • Loading branch information
Sam Stenvall committed Oct 3, 2019
1 parent e50b5be commit 3c77e6d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 3c77e6d

Please sign in to comment.