1
0
mirror of https://github.com/Intervention/image.git synced 2025-02-06 22:00:38 +01:00

Rewrite Gd\Color::alpha2gd for improved performance

This commit is contained in:
Johnson 2014-08-31 09:43:17 +10:00
parent 994128d98a
commit 6e69e10b2d

View File

@ -215,15 +215,12 @@ class Color extends AbstractColor
*/
private function alpha2gd($input)
{
$range_input = range(1, 0, 1/127);
$range_output = range(0, 127);
$oldMin = 0;
$oldMax = 1;
foreach ($range_input as $key => $value) {
if ($value <= $input) {
return $range_output[$key];
}
}
$newMin = 127;
$newMax = 0;
return 127;
return ceil(((($input- $oldMin) * ($newMax - $newMin)) / ($oldMax - $oldMin)) + $newMin);
}
}