本文整理汇总了PHP中imagechar函数的典型用法代码示例。如果您正苦于以下问题:PHP imagechar函数的具体用法?PHP imagechar怎么用?PHP imagechar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagechar函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkcode
public function checkcode($width = 60, $height = 24, $verifyName = 'checkcode')
{
if (!isset($_SESSION)) {
session_start();
}
$code = "ABCDEFGHKLMNPRSTUVWYZ23456789";
$length = 4;
$randval = '';
for ($i = 0; $i < $length; $i++) {
$char = $code[rand(0, strlen($code) - 1)];
$randval .= $char;
}
$_SESSION[$verifyName] = strtolower($randval);
$width = $length * 10 + 10 > $width ? $length * 10 + 10 : $width;
$im = imagecreate($width, $height);
$backColor = imagecolorallocate($im, 255, 255, 255);
$borderColor = imagecolorallocate($im, 255, 255, 255);
@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
@imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
$fontcolor = imagecolorallocate($im, rand(0, 200), rand(0, 120), rand(0, 120));
for ($i = 0; $i < $length; $i++) {
$fontsize = 5;
$x = floor($width / $length) * $i + 5;
$y = rand(0, $height - 15);
imagechar($im, $fontsize, $x, $y, $randval[$i], $fontcolor);
}
self::output($im, 'png');
}
示例2: render
/**
* 显示验证码
*/
public function render()
{
header('Pragma: no-cache');
header('Cache-Control: no-cache');
header('Content-Type: image/jpeg');
$image = imagecreatetruecolor(79, 25);
$color_Background = imagecolorallocate($image, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
imagefill($image, 0, 0, $color_Background);
$key = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'V', 'W', 'X', 'Y', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'h', 'i', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 't', 'v', 'w', 'x', 'y');
$string = null;
$char_X = mt_rand(1, 20);
$char_Y = 0;
for ($i = 0; $i < 4; $i++) {
$char_Y = mt_rand(1, 6);
$char = $key[mt_rand(0, 49)];
$string .= $char;
$color_Char = imagecolorallocate($image, mt_rand(20, 190), mt_rand(20, 190), mt_rand(20, 190));
imagechar($image, 5, $char_X, $char_Y, $char, $color_Char);
$char_X = $char_X + mt_rand(8, 20);
}
$this->_code = $string;
$_SESSION[self::SESSION_KEY] = $string;
imagegif($image);
imagedestroy($image);
}
示例3: image
/**
* generates the image for the captcha
* @param string $name, used in the session
* @param int $width
* @param int $height
* @param string $baseList
*/
public static function image($name = '', $width = 120, $height = 40, $baseList = '123456789abcdfghjkmnpqrstvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ')
{
//echo $name.' orig= '.Session::instance()->get('captcha_'.$name).'<br>';
$length = mt_rand(3, 5);
//code length
$lines = mt_rand(1, 5);
//to make the image dirty
$image = @imagecreate($width, $height) or die('Cannot initialize GD!');
$code = '';
//code generated saved at session
//base image with dirty lines
for ($i = 0; $i < $lines; $i++) {
imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), imagecolorallocate($image, mt_rand(150, 255), mt_rand(150, 255), mt_rand(150, 255)));
}
//writting the chars
for ($i = 0, $x = 0; $i < $length; $i++) {
$actChar = substr($baseList, rand(0, strlen($baseList) - 1), 1);
$x += 10 + mt_rand(0, 10);
imagechar($image, mt_rand(4, 5), $x, mt_rand(5, 20), $actChar, imagecolorallocate($image, mt_rand(0, 155), mt_rand(0, 155), mt_rand(0, 155)));
$code .= strtolower($actChar);
}
Session::instance()->set('captcha_' . $name, $code);
//die( 'changed= '.Session::instance()->get('captcha_'.$name));
// prevent client side caching
header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", FALSE);
header("Pragma: no-cache");
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
}
示例4: create_captha_img
function create_captha_img($char)
{
$width = 100;
$height = 25;
$im = @imagecreate($width, $height) or die("Cannot initialize new GD image stream!");
$char = str_replace(array('a', 'b', 'c', 'd', 'e', 'f'), array('1', '5', '8', '2', '7', '9'), $char);
$char = substr($char, 1, 4);
imagecolortransparent($im, imagecolorallocate($im, 205, 255, 255));
for ($i = 0; $i < strlen($char); $i++) {
$text_color = imagecolorallocate($im, rand(200, 255), rand(0, 120), rand(0, 120));
$x = $width / 10 + $i * ($width / 5);
$y = 0;
imagechar($im, 4, $x, $y, chr(rand(65, 90)), $text_color);
}
imageline($im, 1, rand(5, 10), $width - 10, rand(5, 10), imagecolorallocatealpha($im, rand(180, 255), rand(0, 120), rand(0, 120), 60));
for ($i = 0; $i < strlen($char); $i++) {
$text_color = imagecolorallocate($im, rand(0, 180), rand(0, 180), rand(0, 180));
$x = rand(0, 5) + $i * $width / rand(4, 5);
$y = rand(8, 12);
imagechar($im, 5, $x, $y, $char[$i], $text_color);
}
ob_start();
imagepng($im);
$src = 'data:image/png;base64,' . base64_encode(ob_get_contents());
ob_end_clean();
imagedestroy($im);
return $src;
}
示例5: verify_code
function verify_code()
{
$randCode = '';
$chars = 'abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPRSTUVWXYZ23456789';
for ($i = 0; $i < 5; $i++) {
$randCode .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
$img = imagecreate(70, 22);
$bgColor = imagecolorallocate($img, 255, 255, 255);
$pixColor = imagecolorallocate($img, mt_rand(30, 180), mt_rand(10, 100), mt_rand(40, 250));
for ($i = 0; $i < 5; $i++) {
$x = $i * 13 + mt_rand(0, 4) - 2;
$y = mt_rand(0, 3);
$text_color = imagecolorallocate($img, mt_rand(30, 180), mt_rand(10, 100), mt_rand(40, 250));
imagechar($img, 5, $x + 5, $y + 3, $randCode[$i], $text_color);
}
for ($j = 0; $j < 60; $j++) {
$x = mt_rand(0, 70);
$y = mt_rand(0, 22);
imagesetpixel($img, $x, $y, $pixColor);
}
$_SESSION['code'] = $randCode;
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
}
示例6: getCaptcha
/**
* 生成验证码
* @param int $width 验证码图片宽度.默认130
* @param int $height 验证码图片高度.默认40
* @param int $fontSize 验证码字体大小.默认20
* @param int $length 验证码字符个数.默认4
* @return string 验证码中的字符串
*/
public static function getCaptcha($width = '130', $height = '40', $fontSize = '20', $length = '4')
{
$chars = '0123456789abcdefghijklmnopqrstuvwxyz';
$randStr = substr(str_shuffle($chars), 0, $length);
$image = imagecreatetruecolor($width, $height);
// 定义背景色
$bgColor = imagecolorallocate($image, 0xff, 0xff, 0xff);
// 定义文字及边框颜色
$blackColor = imagecolorallocate($image, 0x0, 0x0, 0x0);
//生成矩形边框
imagefilledrectangle($image, 0, 0, $width, $height, $bgColor);
// 循环生成雪花点
for ($i = 0; $i < 200; $i++) {
$grayColor = imagecolorallocate($image, 128 + rand(0, 128), 128 + rand(0, 128), 128 + rand(0, 128));
imagesetpixel($image, rand(1, $width - 2), rand(4, $height - 2), $grayColor);
}
$font = ROOT_PATH . 'resources/fonts/acidic.ttf';
// 把随机字符串输入图片
$i = -1;
while (isset($randStr[++$i])) {
$fontColor = imagecolorallocate($image, rand(0, 100), rand(0, 100), rand(0, 100));
if (!function_exists('imagettftext')) {
imagechar($image, $fontSize, 15 + $i * 30, rand(5, 20), $randStr[$i], $fontColor);
} else {
imagettftext($image, $fontSize, 0, 10 + $i * 30, rand(25, 35), $fontColor, $font, $randStr[$i]);
}
}
imagepng($image);
$image = $bgColor = $blackColor = $grayColor = $fontColor = null;
return $randStr;
}
示例7: newVerify
public static function newVerify($width = 60, $height = 25)
{
$im = imagecreate($width, $height);
$backgroundcolor = imagecolorallocate($im, 255, 255, 255);
$mCheckCodeNum = 4;
$mCheckCode = '';
for ($i = 0; $i < $mCheckCodeNum; $i++) {
$mCheckCode .= strtoupper(chr(rand(97, 122)));
}
$session = new XF_Session('XF_ImageVerify');
$session->write(strtolower($mCheckCode));
for ($i = 0; $i <= 64; $i++) {
$pointcolor = imagecolorallocate($im, mt_rand(1, 155), mt_rand(0, 200), mt_rand(1, 155));
imagesetpixel($im, mt_rand(0, $width - 1), mt_rand(0, $height - 1), $pointcolor);
}
$snowflake_size = 5;
for ($i = 0; $i < $mCheckCodeNum; $i++) {
$font_color = imagecolorallocate($im, mt_rand(1, 155), mt_rand(1, 200), 100);
$x = floor($width / $mCheckCodeNum) * $i + 3;
$y = rand(0, $height - 15);
imagechar($im, $snowflake_size, $x, $y, $mCheckCode[$i], $font_color);
}
$bordercolor = imagecolorallocate($im, 188, 188, 188);
imagerectangle($im, 0, 0, $width - 1, $height - 1, $bordercolor);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
}
示例8: writeCheckCodeToImage
private function writeCheckCodeToImage()
{
for ($i = 0; $i <= $this->codenum; $i++) {
$bg_color = imagecolorallocate($this->checkimage, rand(0, 255), rand(0, 128), rand(0, 255));
$x = floor($this->width / $this->codenum) * $i + 2;
$y = rand(1, $this->height - 15);
imagechar($this->checkimage, rand(5, 8), $x, $y, $this->checkcode[$i], $bg_color);
}
}
示例9: WriteCheckCodeToImage
/**
* @write code to Image
*/
function WriteCheckCodeToImage()
{
for ($i = 0; $i <= $this->mCheckCodeNum; $i++) {
$bg_color = imagecolorallocate($this->mCheckImage, rand(0, 255), rand(0, 128), rand(0, 255));
$x = floor($this->mCheckImageWidth / $this->mCheckCodeNum) * $i;
$y = rand(0, $this->mCheckImageHeight - 15);
imagechar($this->mCheckImage, 5, $x, $y, $this->mCheckCode[$i], $bg_color);
}
}
示例10: outputtext
private function outputtext()
{
for ($i = 0; $i < $this->codeNum; $i++) {
$fontcolor = imagecolorallocate($this->image, rand(0, 128), rand(0, 128), rand(0, 128));
$fontsize = rand(3, 5);
$x = floor($this->width / $this->codeNum) * $i + 3;
$y = rand(0, $this->height - imagefontheight($fontsize));
imagechar($this->image, $fontsize, $x, $y, $this->checkcode[$i], $fontcolor);
}
}
示例11: outputText
private function outputText()
{
for ($i = 0; $i <= $this->codeNum; $i++) {
$bg_color = imagecolorallocate($this->image, mt_rand(0, 255), mt_rand(0, 128), mt_rand(0, 255));
$x = floor($this->width / $this->codeNum) * $i + 3;
$y = mt_rand(0, $this->height - 15);
$str = substr($this->checkCode, $i, 1);
imagechar($this->image, 5, $x, $y, $str, $bg_color);
}
}
示例12: setCaptcha
private function setCaptcha()
{
for ($i = 0; $i < $this->codeNum; $i++) {
$color = imagecolorallocate($this->im, rand(50, 250), rand(100, 250), rand(128, 250));
$size = rand(floor($this->height / 5), floor($this->height / 3));
$x = floor($this->width / $this->codeNum) * $i + 5;
$y = rand(0, $this->height - 20);
imagechar($this->im, $size, $x, $y, $this->code[$i], $color);
}
}
示例13: outputText
private function outputText()
{
for ($i = 0; $i < $this->codeNum; $i++) {
$bg_color = imagecolorallocate($this->image, rand(0, 255), rand(0, 128), rand(0, 255));
$x = floor($this->width / $this->codeNum) * $i + 3;
$y = rand(0, $this->height - 15);
//echo $this->checkCode;
imagechar($this->image, 5, $x, $y, $this->checkCode[$i], $bg_color);
}
}
示例14: outstring
private function outstring()
{
for ($i = 0; $i < $this->num; $i++) {
$color = imagecolorallocate($this->img, rand(0, 128), rand(0, 128), rand(0, 128));
$fontsize = rand(3, 5);
$x = 3 + $this->width / $this->num * $i;
$y = rand(0, imagefontheight($fontsize) - 3);
imagechar($this->img, $fontsize, $x, $y, $this->code[$i], $color);
}
}
示例15: drawCode
private function drawCode()
{
for ($i = 0; $i < $this->codeLen; $i++) {
$color = imagecolorallocate($this->img, mt_rand(0, 128), mt_rand(0, 128), mt_rand(0, 128));
$fontsize = mt_rand(5, 8);
$x = 3 + $this->codeWidth / $this->codeLen * $i;
$y = rand(2, imagefontheight($fontsize) - 10);
imagechar($this->img, $fontsize, $x, $y, $this->code[$i], $color);
}
return;
}