1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-15 10:23:59 +02:00

Merge pull request #220 from jwpage/faster_alpha2gd

Rewrite Gd\Color::alpha2gd for improved performance
This commit is contained in:
Oliver Vogel
2014-08-31 11:30:21 +02:00

View File

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