本文整理汇总了PHP中Number::minmax方法的典型用法代码示例。如果您正苦于以下问题:PHP Number::minmax方法的具体用法?PHP Number::minmax怎么用?PHP Number::minmax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Number
的用法示例。
在下文中一共展示了Number::minmax方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: text_image
/**
* Create a GD image with text.
*
* @param string $text The text to use. TTF fonts accept HTML character codes.
* @param integer $size Fontsize in pixels. For non-truetype fonts, size has a range of [1-5] points.
* @param integer $padding Padding in pixels arround the text
* @param string $color Color of the text
* @param string $background Background for the text. Default is transparent background.
* @param integer $radius Radius of rounded corners ont eh background if desired
* @return resource GD resource with text.
*/
public function text_image($text, $size = 24, $padding = 0, $color = "#ffffff", $background = 'transparent', $radius = 10)
{
if ($this->ttfont) {
# Decode any htmls special chars, insert copyright date
$text = html_entity_decode($text) . ' ' . chr(169) . date('Y');
# Get our bounding box coordinates to find width and height.
$bbox = imagettfbbox($size, 0, $this->ttfont, $text);
$w = abs($bbox[4] - $bbox[0]) + $padding * 2;
$h = abs($bbox[5] - $bbox[0]) + $padding * 2;
# Center horizontally
$x = $padding;
# Center vertically
$y = $h - $padding;
} else {
# Insert copyright date
$text = $text . ' (c)' . date('Y');
$size = Number::minmax($size, 1, 5);
$w = imagefontwidth($size) * strlen($text) + 2 * $padding;
$h = imagefontheight($size) + 2 * $padding;
# Center horizontally, vertically
$x = $y = $padding;
}
# Blank canvas
$stamp = imagecreatetruecolor($w, $h);
# Allocate Transparent background
imagefill($stamp, 0, 0, imagecolorallocatealpha($stamp, 0, 0, 0, 127));
# Add (rounded) rectangle to background if desired
if ($background != 'transparent') {
$this->imagefillroundedrect($stamp, 0, 0, $w, $h, $radius, $background, 1);
}
# Allocate Text Color
$tcol = Color::hex2rgb($color);
$tcol = imagecolorallocatealpha($stamp, $tcol[0], $tcol[1], $tcol[2], 0);
# Allocate text using Truetype font if available
if ($this->ttfont) {
imageTTFText($stamp, $size, 0, $x, $y, $tcol, $this->ttfont, $text);
} else {
imagestring($stamp, $size, $x, $y, $text, $tcol);
}
return $stamp;
}