本文整理汇总了PHP中Number::normalize方法的典型用法代码示例。如果您正苦于以下问题:PHP Number::normalize方法的具体用法?PHP Number::normalize怎么用?PHP Number::normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Number
的用法示例。
在下文中一共展示了Number::normalize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: alpha
/**
* Modify image opacity. To work correctly image must be saved in PNG or GIF format.
*
* @param mixed $alpha Default is float in range [0-1], however setting omega allows for custom input range.
* @param integer $omega Adjustment sensitivity. User may enter +/- this value and the output will be normalized for safe function usage
* @return mixed On success, current object to allow function chaining. False otherwise.
*/
public function alpha($alpha = 0.5, $omega = false)
{
# Normalize input if desired.
if ($omega !== false) {
$alpha = Number::normalize($alpha, 0, 1, $omega);
}
# Convert CSS alpha to GD ranges
$alpha = Color::alpha2gd(Number::minmax($alpha, 0, 1));
# Set image boundaries
$width = imagesx($this->img);
$height = imagesy($this->img);
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
# Extract Bits
$rgb = imagecolorat($this->img, $x, $y);
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$a = ($rgb & 0xff000000) >> 24;
# Modify alpha
$a += $alpha;
# Boundary checks
$a = $a > 127 ? 127 : ($a < 0 ? 0 : $a);
# Inject pixel with alpha
if (!imagesetpixel($this->img, $x, $y, imagecolorallocatealpha($this->img, $r, $g, $b, $a))) {
return false;
}
}
}
# Apply filter. On success update filename and return current object for function chaining, false on error.
return $this->update(__FUNCTION__, func_get_args());
}