本文整理匯總了PHP中ImageColorallocate函數的典型用法代碼示例。如果您正苦於以下問題:PHP ImageColorallocate函數的具體用法?PHP ImageColorallocate怎麽用?PHP ImageColorallocate使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ImageColorallocate函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: create_captcha
function create_captcha($width = 60, $height = 32)
{
session_start();
//生成驗證碼圖片
Header("Content-type: image/PNG");
$im = imagecreate($width, $height);
// width and height of image
$back = ImageColorAllocate($im, 245, 245, 245);
// specify background color
imagefill($im, 0, 0, $back);
// fill the background color into image
$vcodes = "";
srand((double) microtime() * 1000000);
//生成4位數字
for ($i = 0; $i < 4; $i++) {
$font = ImageColorAllocate($im, rand(100, 255), rand(0, 100), rand(100, 255));
// 生成隨機顏色
$authnum = rand(1, 9);
$vcodes .= $authnum;
imagestring($im, 5, 2 + $i * 10, 1, $authnum, $font);
}
for ($i = 0; $i < 100; $i++) {
// interuppting
$randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
// 畫像素點函數
}
ImagePNG($im);
ImageDestroy($im);
$_SESSION['captcha'] = $vcodes;
}
示例2: create_captcha
function create_captcha()
{
session_start();
//生成驗證碼圖片
Header("Content-type: image/PNG");
$im = imagecreate(44, 18);
// 畫一張指定寬高的圖片
$back = ImageColorAllocate($im, 245, 245, 245);
// 定義背景顏色
imagefill($im, 0, 0, $back);
//把背景顏色填充到剛剛畫出來的圖片中
$vcodes = "";
srand((double) microtime() * 1000000);
//生成4位數字
for ($i = 0; $i < 4; $i++) {
$font = ImageColorAllocate($im, rand(100, 255), rand(0, 100), rand(100, 255));
// 生成隨機顏色
$authnum = rand(1, 9);
$vcodes .= $authnum;
imagestring($im, 5, 2 + $i * 10, 1, $authnum, $font);
}
$_SESSION['VCODE'] = $vcodes;
for ($i = 0; $i < 100; $i++) {
$randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
// 畫像素點函數
}
ImagePNG($im);
ImageDestroy($im);
}
示例3: getAuthImage
function getAuthImage($text)
{
$this->setpin($text);
$im_x = 160;
$im_y = 40;
$im = imagecreatetruecolor($im_x, $im_y);
$text_c = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
$tmpC0 = mt_rand(100, 255);
$tmpC1 = mt_rand(100, 255);
$tmpC2 = mt_rand(100, 255);
$buttum_c = ImageColorAllocate($im, $tmpC0, $tmpC1, $tmpC2);
imagefill($im, 16, 13, $buttum_c);
$font = PATH_SYS_PUBLIC . 'font-awesome/fonts/verdana.ttf';
for ($i = 0; $i < strlen($text); $i++) {
$tmp = substr($text, $i, 1);
$array = array(-1, 1);
$p = array_rand($array);
$an = $array[$p] * mt_rand(1, 10);
//角度
$size = 28;
imagettftext($im, $size, $an, 15 + $i * $size, 35, $text_c, $font, $tmp);
}
$distortion_im = imagecreatetruecolor($im_x, $im_y);
imagefill($distortion_im, 16, 13, $buttum_c);
for ($i = 0; $i < $im_x; $i++) {
for ($j = 0; $j < $im_y; $j++) {
$rgb = imagecolorat($im, $i, $j);
if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 2 * M_PI - M_PI * 0.1) * 4), $j, $rgb);
}
}
}
//加入幹擾象素;
$count = 160;
//幹擾像素的數量
for ($i = 0; $i < $count; $i++) {
$randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
}
$rand = mt_rand(5, 30);
$rand1 = mt_rand(15, 25);
$rand2 = mt_rand(5, 10);
for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
for ($px = -80; $px <= 80; $px = $px + 0.1) {
$x = $px / $rand1;
if ($x != 0) {
$y = sin($x);
}
$py = $y * $rand2;
imagesetpixel($distortion_im, $px + 80, $py + $yy, $text_c);
}
}
//設置文件頭;
Header("Content-type: image/JPEG");
//以PNG格式將圖像輸出到瀏覽器或文件;
ImagePNG($distortion_im);
//銷毀一圖像,釋放與image關聯的內存;
ImageDestroy($distortion_im);
ImageDestroy($im);
}
示例4: rand_create
function rand_create()
{
//通知瀏覽器將要輸出PNG圖片
Header("Content-type: image/PNG");
//準備好隨機數發生器種子
srand((double) microtime() * 1000000);
//準備圖片的相關參數
$im = imagecreate(62, 20);
$black = ImageColorAllocate($im, 0, 0, 0);
//RGB黑色標識符
$white = ImageColorAllocate($im, 255, 255, 255);
//RGB白色標識符
$gray = ImageColorAllocate($im, 200, 200, 200);
//RGB灰色標識符
//開始作圖
imagefill($im, 0, 0, $gray);
while (($randval = rand() % 100000) < 10000) {
}
$_SESSION["login_check_num"] = $randval;
//將四位整數驗證碼繪入圖片
imagestring($im, 5, 10, 3, $randval, $black);
//加入幹擾象素
for ($i = 0; $i < 200; $i++) {
$randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
}
//輸出驗證圖片
ImagePNG($im);
//銷毀圖像標識符
ImageDestroy($im);
}
示例5: getAuthImage
static function getAuthImage($text, $w = 200, $h = 40)
{
$im_x = $w;
$im_y = $h;
$im = imagecreatetruecolor($im_x, $im_y);
$text_c = imagecolorallocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
$button_c = imagecolorallocate($im, mt_rand(100, 255), mt_rand(100, 255), mt_rand(100, 255));
imagefill($im, 16, 13, $button_c);
$font = realpath(THINK_PATH . 'Common/Class/VerifyCode/') . '\\t1.ttf';
$len = strlen($text);
$mt_array = array(-1, 1);
$size = 28;
for ($i = 0; $i < $len; $i++) {
$tmp = substr($text, $i, 1);
$p = array_rand($mt_array);
$an = $mt_array[$p] * mt_rand(1, 10);
//角度
imagettftext($im, $size, $an, 15 + $i * $size, 35, $text_c, $font, $tmp);
}
$distortion_im = imagecreatetruecolor($im_x, $im_y);
imagefill($distortion_im, 16, 13, $button_c);
for ($i = 0; $i < $im_x; $i++) {
for ($j = 0; $j < $im_y; $j++) {
$rgb = imagecolorat($im, $i, $j);
if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 2 * M_PI - M_PI * 0.1) * 4), $j, $rgb);
}
}
}
//加入幹擾象素;
$count = 160;
//幹擾像素的數量
for ($i = 0; $i < $count; $i++) {
$randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
}
$rand = mt_rand(5, 30);
$rand1 = mt_rand(15, 25);
$rand2 = mt_rand(5, 10);
for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
for ($px = -80; $px <= 80; $px = $px + 0.1) {
$x = $px / $rand1;
if ($x != 0) {
$y = sin($x);
}
$py = $y * $rand2;
imagesetpixel($distortion_im, $px + 80, $py + $yy, $text_c);
}
}
//設置文件頭;
Header("Content-type: image/JPEG");
//以PNG格式將圖像輸出到瀏覽器或文件;
ImagePNG($distortion_im);
//銷毀一圖像,釋放與image關聯的內存;
ImageDestroy($distortion_im);
ImageDestroy($im);
}
示例6: getAuthImage
function getAuthImage($text, $im_x, $im_y, $move_x, $move_y, $font_size, $count)
{
$im = imagecreatetruecolor($im_x, $im_y);
$text_c = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
$tmpC0 = mt_rand(100, 255);
$tmpC1 = mt_rand(100, 255);
$tmpC2 = mt_rand(100, 255);
$buttum_c = ImageColorAllocate($im, $tmpC0, $tmpC1, $tmpC2);
imagefill($im, 16, 13, $buttum_c);
$font = '../font/Airbus.ttf';
for ($i = 0; $i < strlen($text); $i++) {
$tmp = substr($text, $i, 1);
$array = array(-1, 1);
$p = array_rand($array);
$an = $array[$p] * mt_rand(1, 10);
$size = $font_size;
imagettftext($im, $size, $an, $i * $size + $move_x, $move_y, $text_c, $font, $tmp);
}
$distortion_im = imagecreatetruecolor($im_x, $im_y);
imagefill($distortion_im, 16, 13, $buttum_c);
for ($i = 0; $i < $im_x; $i++) {
for ($j = 0; $j < $im_y; $j++) {
$rgb = imagecolorat($im, $i, $j);
if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 1 * M_PI - M_PI * 0.1) * 1), $j, $rgb);
}
}
}
for ($i = 0; $i < $count; $i++) {
$randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
}
$rand = mt_rand(5, 30);
$rand1 = mt_rand(1, 25);
$rand2 = mt_rand(5, 10);
for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
for ($px = -80; $px <= 80; $px = $px + 0.1) {
$x = $px / $rand1;
if ($x != 0) {
$y = sin($x);
}
$py = $y * $rand2;
//imagesetpixel($distortion_im, $px+80, $py+$yy, $text_c);
}
}
Header("Content-type: image/JPEG");
ImagePNG($distortion_im);
ImageDestroy($distortion_im);
ImageDestroy($im);
}
示例7: captcha
public function captcha()
{
$this->load->library('session');
//生成驗證碼圖片
header("Content-type: image/png");
//要顯示的字符,可自己進行增刪
$str = "1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,m,n,p,q,r,s,t,y,z";
$list = explode(",", $str);
$cmax = count($list) - 1;
$verifyCode = '';
for ($i = 0; $i < 5; $i++) {
$randnum = mt_rand(0, $cmax);
//取出字符,組合成驗證碼字符
$verifyCode .= $list[$randnum];
}
//避免程序讀取session字符串破解,生成的驗證碼用MD5加密一下再放入session,提交的驗證碼md5以後和seesion存儲的md5進行對比
//直接md5還不行,別人反向md5後提交還是可以的,再加個特定混淆碼再md5強度才比較高,總長度在14位以上
//網上有反向md5的 Rainbow Table,64GB的量幾分鍾內就可以搞定14位以內大小寫字母、數字、特殊字符的任意排列組合的MD5反向
//但這種方法不能避免直接分析圖片上的文字進行破解,生成gif動畫比較難分析出來
//加入前綴、後綴字符,prestr endstr 為自定義字符,將最終字符放入SESSION中
//$_SESSION['randcode'] = md5($this->prestr.$verifyCode.$this->endstr);
$this->session->set_userdata('randcode', md5($this->session_prestr . $verifyCode . $this->session_endstr));
//生成圖片
$im = imagecreate(65, 30);
//此條及以下三條為設置的顏色
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
$gray = imagecolorallocate($im, 200, 200, 200);
$red = imagecolorallocate($im, 255, 0, 0);
$blue = imagecolorallocate($im, 52, 126, 189);
//給圖片填充顏色
imagefill($im, 0, 0, $white);
//將驗證碼寫入到圖片中
imagestring($im, 5, 10, 8, $verifyCode, $blue);
//加入幹擾象素
for ($i = 0; $i < 50; $i++) {
$randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
}
imagepng($im);
imagedestroy($im);
}
示例8: display
/**
* 獲取生成的Code
*
* @return [type] [description]
*/
public function display()
{
header("Content-type: image/PNG");
$im = imagecreate(52, 20);
$black = ImageColorallocate($im, 0, 0, 0);
$white = ImageColorallocate($im, 230, 255, 255);
$gray = ImageColorallocate($im, 200, 200, 255);
$blue = ImageColorallocate($im, 40, 100, 225);
imagefill($im, 0, 0, $white);
$_SESSION['_authcode'] = $this->genCode();
$authnum = $_SESSION['_authcode'];
imagestring($im, 6, 8, 3, $authnum, $blue);
for ($i = 0; $i < 200; $i++) {
$randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
exit;
}
示例9: createCaptcha
/**
* @throws Exception
* 生成驗證碼 , 存放到token相對應的session裏麵
*/
public function createCaptcha()
{
$token = $_COOKIE["token"];
if (empty($token)) {
throw new Exception("無法生產驗證碼,請稍後在試");
}
$string = "abcdefghijklmnopqrstuvwxyz0123456789";
$str = "";
for ($i = 0; $i < 4; $i++) {
$pos = rand(0, 35);
$str .= $string[$pos];
}
$this->load->library('session');
$flag = $this->session->set_userdata($token . "_captcha", $str);
$img_handle = Imagecreate(80, 20);
//圖片大小80X20
$back_color = ImageColorAllocate($img_handle, 255, 255, 255);
//背景顏色(白色)
$txt_color = ImageColorAllocate($img_handle, 0, 0, 0);
//文本顏色(黑色)
//加入幹擾線
for ($i = 0; $i < 3; $i++) {
$line = ImageColorAllocate($img_handle, rand(0, 255), rand(0, 255), rand(0, 255));
Imageline($img_handle, rand(0, 15), rand(0, 15), rand(100, 150), rand(10, 50), $line);
}
//加入幹擾象素
for ($i = 0; $i < 200; $i++) {
$randcolor = ImageColorallocate($img_handle, rand(0, 255), rand(0, 255), rand(0, 255));
Imagesetpixel($img_handle, rand() % 100, rand() % 50, $randcolor);
}
Imagefill($img_handle, 0, 0, $back_color);
//填充圖片背景色
ImageString($img_handle, 28, 20, 0, $str, $txt_color);
//水平填充一行字符串
ob_clean();
// ob_clean()清空輸出緩存區
header("Content-type: image/png");
//生成驗證碼圖片
Imagepng($img_handle);
//顯示圖片
}
示例10: authCodeAction
public function authCodeAction()
{
session_start();
//生成驗證碼圖片
Header("Content-type: image/PNG ");
srand((double) microtime() * 1000000);
$authnum = rand(1000, 9999);
$_SESSION['rand_code'] = $authnum;
$im = imagecreate(62, 20);
ImageColorAllocate($im, 0, 0, 0);
$white = ImageColorAllocate($im, 255, 255, 255);
//將五位整數驗證碼繪入圖片
imagestring($im, 5, 10, 3, $authnum, $white);
//加入幹擾象素
for ($i = 0; $i < 200; $i++) {
$randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($im, rand() % 70, rand() % 30, $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
}
示例11: handle_request
public function handle_request()
{
$params = APF::get_instance()->get_request()->get_parameters();
$cookiename = @$params['cn'];
$x_size = $params['x'];
$y_size = $params['y'];
$num_size = $params['s'];
//添加字符數量
$font_num = isset($params['n']) ? $params['n'] : 4;
$x1 = $params['x1'];
$y1 = $params['y1'];
$x2 = $params['x2'];
$y2 = $params['y2'];
$seccode = $this->random($font_num, 1);
$md5seccode = Util_AuthorCrypt::encrypt($seccode, md5($_SERVER['HTTP_USER_AGENT']));
// if('askquestionreg'==$cookiename){
// $objMem=APF_Cache_Factory::get_instance()->get_memcache();
// $strGUID=APF::get_instance()->get_request()->get_cookie('aQQ_ajkguid');
// $objMem->set('askquestionreg_'.$strGUID,$md5seccode,0,90);
// }
APF::get_instance()->get_response()->set_cookie($cookiename, $md5seccode, 30 * 60);
header("Content-type: image/png");
$im = imagecreatetruecolor($x_size, $y_size);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, $x_size, $y_size, $white);
$font = APF::get_instance()->get_config("FontsUrl");
//var_dump($font);exit;
imagettftext($im, $num_size, 2, $x1, $y1, $grey, $font, $seccode);
imagettftext($im, $num_size, 2, $x2, $y2, $black, $font, $seccode);
for ($i = 0; $i < 600; $i++) {
$randcolor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($im, rand() % $x_size, rand() % $y_size, $randcolor);
}
imagepng($im);
imagedestroy($im);
return false;
}
示例12: handle_request
public function handle_request()
{
$params = APF::get_instance()->get_request()->get_parameters();
$x_size = $params['x'];
$y_size = $params['y'];
$num_size = $params['s'];
//添加字符數量
$font_num = isset($params['n']) ? $params['n'] : 4;
$x1 = $params['x1'];
$y1 = $params['y1'];
$x2 = $params['x2'];
$y2 = $params['y2'];
$verifyCode = strtolower($this->random($font_num, 1));
$keySuffix = md5($_SERVER['HTTP_USER_AGENT'] . $verifyCode);
Bll_Security_Verify::saveVerifyCode($keySuffix, $verifyCode);
$response = APF::get_instance()->get_response();
$response->set_content_type('image/png');
$response->set_cookie('sv', $keySuffix, 10 * 60, NULL, NULL, FALSE, TRUE);
$response->set_cache_control('private');
$response->set_header('Expires', 'Thu Jun 05 2014 11:41:06 GMT');
$response->set_header('hash', $keySuffix);
$response->set_header('Pragma', 'no-cache');
$im = imagecreatetruecolor($x_size, $y_size);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, $x_size, $y_size, $white);
$font = APF::get_instance()->get_config("FontsUrl");
imagettftext($im, $num_size, 2, $x1, $y1, $grey, $font, $verifyCode);
imagettftext($im, $num_size, 2, $x2, $y2, $black, $font, $verifyCode);
for ($i = 0; $i < 600; $i++) {
$randColor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
imagesetpixel($im, rand() % $x_size, rand() % $y_size, $randColor);
}
imagepng($im);
imagedestroy($im);
return false;
}
示例13: ob_start
<?php
ob_start();
if (!isset($_SESSION)) {
session_start();
}
header('content-Type:image/gif');
echo mt_srand(time());
const width = 105;
const height = 33;
$length = strlen($_SESSION['ans_checknum']);
$img = imagecreate(width, height);
imagefill($img, 0, 0, ImageColorAllocate($img, 200, 200, 200));
for ($i = 0; $i < 250; $i++) {
$randcolor = ImageColorallocate($img, rand(10, 250), rand(10, 250), rand(10, 250));
imagesetpixel($img, rand() % width, rand() % height, $randcolor);
}
for ($i = 0; $i < $length; $i++) {
$color = imagecolorallocate($img, abs(mt_rand() % 128), abs(mt_rand() % 128), abs(mt_rand() % 128));
imagechar($img, height / 2, abs(mt_rand() % width / 8) + $i * width / 4, abs(mt_rand() % height / 2), $_SESSION['ans_checknum'][$i], $color);
}
imagegif($img);
imageDestroy($img);
ob_end_flush();
示例14: verify
public function verify()
{
//Image::buildImageVerify();
$text = $this->make_rand(4);
$_SESSION['verify'] = md5(strtolower($text));
$im_x = 160;
$im_y = 40;
$im = imagecreatetruecolor($im_x, $im_y);
$text_c = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
$tmpC0 = mt_rand(100, 255);
$tmpC1 = mt_rand(100, 255);
$tmpC2 = mt_rand(100, 255);
$buttum_c = ImageColorAllocate($im, $tmpC0, $tmpC1, $tmpC2);
imagefill($im, 16, 13, $buttum_c);
$font = $_SERVER['DOCUMENT_ROOT'] . '/tpl/' . MODULE_NAME . '/default/common/t1.ttf';
for ($i = 0; $i < strlen($text); $i++) {
$tmp = substr($text, $i, 1);
$array = array(-1, 1);
$p = array_rand($array);
$an = $array[$p] * mt_rand(1, 10);
//角度
$size = 28;
imagettftext($im, $size, $an, 15 + $i * $size, 35, $text_c, $font, $tmp);
}
$distortion_im = imagecreatetruecolor($im_x, $im_y);
imagefill($distortion_im, 16, 13, $buttum_c);
for ($i = 0; $i < $im_x; $i++) {
for ($j = 0; $j < $im_y; $j++) {
$rgb = imagecolorat($im, $i, $j);
if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 2 * M_PI - M_PI * 0.1) * 4), $j, $rgb);
}
}
}
//加入幹擾象素;
$count = 160;
//幹擾像素的數量
for ($i = 0; $i < $count; $i++) {
$randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
}
$rand = mt_rand(5, 30);
$rand1 = mt_rand(15, 25);
$rand2 = mt_rand(5, 10);
for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
for ($px = -80; $px <= 80; $px = $px + 0.1) {
$x = $px / $rand1;
if ($x != 0) {
$y = sin($x);
}
$py = $y * $rand2;
imagesetpixel($distortion_im, $px + 80, $py + $yy, $text_c);
}
}
//設置文件頭;
Header("Content-type: image/JPEG");
//以PNG格式將圖像輸出到瀏覽器或文件;
ImagePNG($distortion_im);
//銷毀一圖像,釋放與image關聯的內存;
ImageDestroy($distortion_im);
ImageDestroy($im);
}
示例15: CodeAction
public function CodeAction()
{
$im_x = 100;
$im_y = 35;
$im = imagecreatetruecolor($im_x, $im_y);
$text_c = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
$tmpC0 = mt_rand(100, 255);
$tmpC1 = mt_rand(100, 255);
$tmpC2 = mt_rand(100, 255);
$buttum_c = ImageColorAllocate($im, $tmpC0, $tmpC1, $tmpC2);
imagefill($im, 16, 1, $buttum_c);
$font = 't1.ttf';
$text = $this->make_rand(4);
$session = $this->get('session');
$session->set("code", strtolower($text));
$this->get("logger")->err("========session code:" . $session->get("code"));
$white = ImageColorAllocate($im, 0, 0, 0);
$printtext = "";
for ($index = 0; $index < 4; $index++) {
$printtext .= $text[$index] . " ";
}
ImageString($im, 10, 10, 10, $printtext, $white);
$distortion_im = imagecreatetruecolor($im_x, $im_y);
imagefill($distortion_im, 16, 13, $buttum_c);
for ($i = 0; $i < $im_x; $i++) {
for ($j = 0; $j < $im_y; $j++) {
$rgb = imagecolorat($im, $i, $j);
if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 2 * M_PI - M_PI * 0.1) * 4), $j, $rgb);
}
}
}
//加入幹擾象素;
$count = 150;
//幹擾像素的數量
for ($i = 0; $i < $count; $i++) {
$randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
}
$rand = mt_rand(5, 35);
$rand1 = mt_rand(15, 25);
$rand2 = mt_rand(5, 10);
for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
for ($px = -80; $px <= 80; $px = $px + 0.1) {
$x = $px / $rand1;
if ($x != 0) {
$y = sin($x);
}
$py = $y * $rand2;
imagesetpixel($distortion_im, $px + 50, $py + $yy, $text_c);
}
}
//設置文件頭;
Header("Content-type: image/png");
ImagePNG($distortion_im);
//銷毀一圖像,釋放與image關聯的內存;
ImageDestroy($distortion_im);
ImageDestroy($im);
$response = new Response(json_encode(""));
$response->headers->set('Content-Type', 'text/json');
return $response;
}