/** * @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); //显示图片 }
private function create_do() { $this->im = Imagecreate($this->config['width'], $this->config['height']); //设置背景为白色 Imagecolorallocate($this->im, $this->config['color'][0], $this->config['color'][1], $this->config['color'][2]); //为此背景加个边框 if ($this->config['boxline'] == True) { $bordercolor = Imagecolorallocate($this->im, 37, 37, 37); Imagerectangle($this->im, 0, 0, $this->config['width'] - 1, $this->config['height'] - 1, $bordercolor); } //生成验证码 $this->create_str(); $coder = $_SESSION[$this->config['codname']]; //输入文字 $fontcolor = Imagecolorallocate($this->im, 46, 46, 46); for ($i = 0; $i < $this->config['length']; $i++) { Imagestring($this->im, 5, $i * 10 + 6, rand(2, 5), $coder[$i], $fontcolor); } //加入干扰线 $interfere = $this->config['interfere']; $interfere = $interfere > 30 ? "30" : $interfere; if (!empty($interfere) && $interfere > 1) { for ($i = 1; $i < $interfere; $i++) { $linecolor = Imagecolorallocate($this->im, rand(0, 255), rand(0, 255), rand(0, 255)); $x = rand(1, $this->config['width']); $y = rand(1, $this->config['height']); $x2 = rand($x - 10, $x + 10); $y2 = rand($y - 10, $y + 10); Imageline($this->im, $x, $y, $x2, $y2, $linecolor); } } ob_clean(); Header("Pragma:no-cache\r\n"); Header("Cache-Control:no-cache\r\n"); Header("Expires:0\r\n"); Header("Content-type:Image/jpeg\r\n"); Imagejpeg($this->im); Imagedestroy($this->im); exit; }
function output_png($poll_id, $radius) { if ($radius < 20) { $radius = 90; } $diameter = $radius * 2; $img_size = $diameter + 2; if ($this->is_valid_poll_id($poll_id)) { $img = ImageCreate($img_size, $img_size); for (reset($this->colors); $key = key($this->colors); next($this->colors)) { eval("\$poll_colors[\$key]=ImageColorAllocate(\$img," . $this->colors[$key] . ");"); } ImageFill($img, 0, 0, $poll_colors['blank']); Imagearc($img, $radius, $radius, $diameter, $diameter, 0, 360, $poll_colors['black']); if (!isset($this->options[$poll_id])) { $this->get_poll_data($poll_id); } $totalvotes = $this->options[$poll_id]['total'] == 0 ? 1 : $this->options[$poll_id]['total']; for ($i = 0; $i < sizeof($this->options[$poll_id]['option_id']); $i++) { $img_width = $this->options[$poll_id]['votes'][$i] * 360 / $totalvotes; $end = $this->begin + $img_width; $y1 = sin($end / 180 * M_PI) * $radius; $x1 = cos($end / 180 * M_PI) * $radius; Imageline($img, $radius, $radius, $radius + $x1, $radius + $y1, $poll_colors['black']); $end2 = $this->begin + $img_width * 0.5; $x2 = (int) ($radius + cos($end2 / 180 * M_PI) * 15); $y2 = (int) ($radius + sin($end2 / 180 * M_PI) * 15); Imagefilltoborder($img, $x2, $y2, $poll_colors['black'], $poll_colors[$this->options[$poll_id]['color'][$i]]); $this->begin += $img_width; } $this->begin = 0; ImageColorTransparent($img, $poll_colors['blank']); ImagePNG($img); } else { $loc = "{$pollvars['base_url']}/image/error.png"; header("Location: {$loc}"); exit; } }
// display percent $percent = $total == 0 ? 0 : intval(round($value / $total * 100)); ImageString($im, 3, $x - 24, $y - 4, $percent . "%", $black); // value right side rectangle $percent = $total == 0 ? 0 : intval(round($value / $total * 100)); $px = $x + $percent * $unit; if ($item_title == 'Views') { // draw rectangle value ImageFilledRectangle($im, $x, $y - 2, $px, $y + $bar_width, $barViews); } else { ImageFilledRectangle($im, $x, $y - 2, $px, $y + $bar_width, $barClicks); } // draw empty rectangle ImageRectangle($im, $x, $y - 2, $x + 100 * $unit, $y + $bar_width, $line); // line Imageline($im, $px, $y - 2, $px, $y + $bar_width, $line); // display numbers $fwidth = ImageFontWidth(2); $string = $value . "/" . $total; ImageString($im, 2, $x + 100 * $unit - strlen($string) * $fwidth + 2, $y + 12, $string, $black); } $y = $y + ($bar_width + 20); // IE workaround: Turn off outputbuffering // if zlib compression is turned on if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') > 0 && function_exists('ini_get') && ini_get("zlib.output_compression")) { ob_end_clean(); } // Send the content-type header phpAds_GDContentType(); // Display modified image phpAds_GDShowImage($im);
function display($db_object, $common, $user_id, $default, $error_msg, $learning, $get_var) { $width = 340; $height = 220; $labelfont = 2; $labelfont1 = 1; $labeltitlefont = '3'; $image = ImageCreate($width, $height); while (list($kk, $vv) = @each($get_var)) { ${$kk} = $vv; } //from table $config_table = $common->prefix_table("config"); $color_qry = "select commit_color,accomplish_color from {$config_table} where id='1'"; $res = $db_object->get_a_line($color_qry); $ccolor = $res['commit_color']; $acolor = $res['accomplish_color']; $com = $common->split_color($db_object, $ccolor); $accom = $common->split_color($db_object, $acolor); $p1 = "0x{$com['0']}"; $p2 = "0x{$com['1']}"; $p3 = "0x{$com['2']}"; $p1 = hexdec($p1); $p2 = hexdec($p2); $p3 = hexdec($p3); $bgcolor = ImageColorAllocate($image, 0xffffff, 0xffffff, 0xffffff); $border = ImageColorAllocate($image, 0x0, 0x0, 0x0); $commit_color = imagecolorallocate($image, $p1, $p2, $p3); $red = imagecolorallocate($image, 0xff, 0x0, 0x0); $green = imagecolorallocate($image, 0x33, 0xcc, 0x0); /* to check $date_array = "2003-11-15,2003-11-20,2003-11-30"; $fulfilled_array = "25,150,10"; $fromdate = "2003-11-13"; $todate ="2003-12-01"; */ $fdate = $fromdate; $tdate = $todate; $fulfilled_array = @explode(",", $fulfilled_array); $date_array = @explode(",", $date_array); $to = split("-", $tdate); $from = split("-", $fdate); $dt1 = mktime(0, 0, 0, $to[1], $to[2], $to[0]); $dt2 = mktime(0, 0, 0, $from[1], $from[2], $from[0]); $dt3 = $dt1 - $dt2; $daydiff = $dt3 / 60 / 60 / 24; $days = $error_msg['cDays'] . " {$fdate} " . $error_msg['cTo'] . " {$tdate} "; ImageRectangle($image, 65, 24, 315, 180, $border); ImageString($image, $labelfont, 15, 19, $error_msg['cExceeds'], $border); ImageString($image, $labelfont, 40, 94, $error_msg['cMet'], $border); ImageString($image, $labelfont, 5, 170, $error_msg['cFellshort'], $border); ImageString($image, $labeltitlefont, 70, 182, "{$days}", $border); Imageline($image, 65, 102, 315, 102, $commit_color); ImageStringUp($image, $labeltitlefont, 15, 140, $error_msg['cExpectation'], $border); $x1 = 65; //$y1 = 180; $startx_val = $x1; $starty_val = 180; //$x2 = 130; //$y2 = 95; $p1 = "0x{$accom['0']}"; $p2 = "0x{$accom['1']}"; $p3 = "0x{$accom['2']}"; $p1 = hexdec($p1); $p2 = hexdec($p2); $p3 = hexdec($p3); $accomplish_color = imagecolorallocate($image, $p1, $p2, $p3); $min = 63; $max = 311; $tot = $max - $min; $count = $daydiff; $interval = @($tot / $count); $interval = sprintf("%01.0f", $interval); //ImageString($image, $labelfont, 15,40, "$fulfilled_array", $border); for ($j = 0; $j <= $count; $j++) { if ($min <= $max) { ImageString($image, $labelfont1, $min, 176, "|", $border); } $min = $min + $interval; } $d_array = array(); $inc = 40; $im_dates = split("-", $fdate); //to calculate the x2 value $odd = array("01", "03", "05", "07", "08", "10", "12"); //Odd months $even = array("04", "06", "09", "11"); //even months for ($d = 0; $d < count($date_array); $d++) { $start_date = $im_dates[2]; $ar = $date_array[$d]; $im_da = split("-", $ar); $dte = $im_da[2]; $m = $im_da[1]; for ($c = 0; $c <= $daydiff; $c++) { if ($dte == $start_date) { $dt_array[] = $c; } $start_date = $start_date + 1; if (in_array($m, $odd)) { if ($start_date == 32) { $start_date = 1; $m = $m + 1; if ($m == 13) { $m = 1; } } } elseif (in_array($m, $even)) { if ($start_date == 31) { $start_date = 1; $m = $m + 1; if ($m == 13) { $m = 1; } } } else { if ($start_date == 29) { $start_date = 1; $m = $m + 1; } } //ImageString($image, $labelfont, 50,$inc,"$start_date", $border); $inc = $inc + 15; } } $inc = 50; for ($i = 0; $i < count($fulfilled_array) - 1; $i++) { $ful = $fulfilled_array[$i]; $dt_val = $dt_array[$i + 1]; $x2 = $startx_val + $interval * $dt_val; //cal using No of Days $div = $ful / 25; $y1 = $starty_val - 19.5 * $div; $ful2 = $fulfilled_array[$i + 1]; $div2 = $ful2 / 25; $y2 = $starty_val - 19.5 * $div2; ImageLine($image, $x1, $y1, $x2, $y2, $accomplish_color); $x1 = $x2; //$y1 = $y2; $d_array = ""; //ImageString($image, $labelfont1,80,$inc,"$x1 : $y1 : $x2 : $y2",$border); $inc = $inc + 10; } header("Content-type: image/png"); Imagepng($image); ImageDestroy($image); }
function display($db_object, $common, $user_id, $default, $error_msg, $learning, $get_var) { //from table //setting color $config_table = $common->prefix_table("config"); $color_qry = "select admin_color,rater1_color,rater2_color,rater3_color,self_color,\n\t\t\t\toverall_color from {$config_table} where id='1'"; $res = $db_object->get_a_line($color_qry); $ad_col = $res['admin_color']; $rt1_col = $res['rater1_color']; $rt2_col = $res['rater2_color']; $rt3_col = $res['rater3_color']; $self_col = $res['self_color']; $over_col = $res['overall_color']; $admin = $common->split_color($db_object, $ad_col); $rt1 = $common->split_color($db_object, $rt1_col); $rt2 = $common->split_color($db_object, $rt2_col); $rt3 = $common->split_color($db_object, $rt3_col); $slf = $common->split_color($db_object, $self_col); $ovr = $common->split_color($db_object, $over_col); //for raters //rater1 $col1_1 = "0x{$rt1['0']}"; $col1_2 = "0x{$rt1['1']}"; $col1_3 = "0x{$rt1['2']}"; $col1_1 = hexdec($col1_1); $col1_2 = hexdec($col1_2); $col1_3 = hexdec($col1_3); //rater2 $col2_1 = "0x{$rt2['0']}"; $col2_2 = "0x{$rt2['1']}"; $col2_3 = "0x{$rt2['2']}"; $col2_1 = hexdec($col2_1); $col2_2 = hexdec($col2_2); $col2_3 = hexdec($col2_3); //rater3 $col3_1 = "0x{$rt3['0']}"; $col3_2 = "0x{$rt3['1']}"; $col3_3 = "0x{$rt3['2']}"; $col3_1 = hexdec($col3_1); $col3_2 = hexdec($col3_2); $col3_3 = hexdec($col3_3); //self $col4_1 = "0x{$slf['0']}"; $col4_2 = "0x{$slf['1']}"; $col4_3 = "0x{$slf['2']}"; $col4_1 = hexdec($col4_1); $col4_2 = hexdec($col4_2); $col4_3 = hexdec($col4_3); //for admin $col5_1 = "0x{$admin['0']}"; $col5_2 = "0x{$admin['1']}"; $col5_3 = "0x{$admin['2']}"; $col5_1 = hexdec($col5_1); $col5_2 = hexdec($col5_2); $col5_3 = hexdec($col5_3); //overall $col6_1 = "0x{$ovr['0']}"; $col6_2 = "0x{$ovr['1']}"; $col6_3 = "0x{$ovr['2']}"; $col6_1 = hexdec($col6_1); $col6_2 = hexdec($col6_2); $col6_3 = hexdec($col6_3); //color setting ends $width = 340; $height = 270; $labelfont = 2; $labelfont1 = 1; $labeltitlefont = '3'; $image = ImageCreate($width, $height); while (list($kk, $vv) = @each($get_var)) { ${$kk} = $vv; } $bgcolor = imagecolorallocate($image, 0xff, 0xff, 0xff); $border = ImageColorAllocate($image, 0, 0, 0); $rater1 = imagecolorallocate($image, $col1_1, $col1_2, $col1_3); $rater2 = imagecolorallocate($image, $col2_1, $col2_2, $col2_3); $rater3 = imagecolorallocate($image, $col3_1, $col3_2, $col3_3); $self = imagecolorallocate($image, $col4_1, $col4_2, $col4_3); $boss = imagecolorallocate($image, $col5_1, $col5_2, $col5_3); $over = imagecolorallocate($image, $col6_1, $col6_2, $col6_3); /* to check $fromdate="2003-11-13"; $todate="2003-11-22"; $ratername="emp,bharathi,admin,karthik"; $raterval="0,1,2:1,0:1,0,2:1,2,0,2"; $date="2003-11-13,2003-11-17,2003-11-22:2003-11-13,2003-11-22:2003-11-13,2003-11-20,2003-11-22:2003-11-13,2003-11-15,2003-11-19,2003-11-22"; */ $fdate = $fromdate; $tdate = $todate; if ($ratername != "") { $rname = @split(",", $ratername); } $rt_val = @split(":", $raterval); $rt_date = @split(":", $date); $from = @split("-", $fdate); $to = @split("-", $tdate); $dt1 = mktime(0, 0, 0, $to[1], $to[2], $to[0]); $dt2 = mktime(0, 0, 0, $from[1], $from[2], $from[0]); $dt3 = $dt1 - $dt2; $daydiff = $dt3 / 60 / 60 / 24; $avg_array = @split(",", $avgrating); $ch_name = @split(":", $combine); $combine_array = array(); for ($na = 0; $na < count($ch_name); $na++) { $cl_name = $ch_name[$na]; $sp_clname = @split("=", $cl_name); $ky = trim($sp_clname[0]); $vl = $sp_clname[1]; $combine_array[$ky] = $vl; } //na loop $days = $error_msg['cDays'] . " {$fdate} " . $error_msg['cTo'] . " {$tdate}"; ImageRectangle($image, 65, 24, 315, 180, $border); ImageString($image, $labelfont, 15, 19, $error_msg['cExceeds'], $border); ImageString($image, $labelfont, 40, 94, $error_msg['cMet'], $border); ImageString($image, $labelfont, 5, 170, $error_msg['cFellshort'], $border); ImageString($image, $labeltitlefont, 70, 182, "{$days}", $border); Imageline($image, 65, 102, 315, 102, $border); ImageStringUp($image, $labeltitlefont, 15, 140, $error_msg['cExpectation'], $border); $x1 = 65; //$y1 = 180; $startx_val = $x1; $starty_val = 180; //$x2 = 130; //$y2 = 95; $min = 63; $max = 311; $tot = $max - $min; $count = $daydiff; $interval = @($tot / $count); $interval = sprintf("%01.0f", $interval); ImageString($image, $labelfont, 15, 24, "", $border); for ($j = 0; $j <= $count; $j++) { if ($min <= $max) { ImageString($image, $labelfont1, $min, 176, "|", $border); } $min = $min + $interval; } $d_array = array(); $inc = 50; $im_dates = split("-", $fdate); //ImageString($image, $labelfont, 50,80,"$im_dates[2]", $border); //to calculate the x2 value. $odd = array("01", "03", "05", "07", "08", "10", "12"); //Odd months $even = array("04", "06", "09", "11"); //even months //ImageString($image, $labelfont, 50,80,"$rt_date[0]", $border); for ($f = 0; $f < count($rt_date); $f++) { $date_arr = $rt_date[$f]; $date_array = @split(",", $date_arr); for ($d = 0; $d < count($date_array); $d++) { $start_date = $im_dates[2]; $ar = $date_array[$d]; $im_da = split("-", $ar); $dte = $im_da[2]; $m = $im_da[1]; for ($c = 0; $c <= $daydiff; $c++) { if ($dte == $start_date) { $dt_array[] = $c; } $start_date = $start_date + 1; if (in_array($m, $odd)) { if ($start_date == 32) { $start_date = 1; $m = $m + 1; if ($m == 13) { $m = 1; } } } elseif (in_array($m, $even)) { if ($start_date == 31) { $start_date = 1; $m = $m + 1; if ($m == 13) { $m = 1; } } } else { if ($start_date == 29) { $start_date = 1; $m = $m + 1; } } } } //d loop } //f loop $d_inc = 0; $color1 = $red; $color2 = $blue; $color3 = $green; $color4 = $rose; $n_inc = 200; for ($i = 0; $i < count($rname); $i++) { $name = $rname[$i]; $avg = $avg_array[$i]; $rtval = $rt_val[$i]; $rtdate = $rt_date[$i]; $rval = @split(",", $rtval); $rdate = @split(",", $rtdate); $pl = $i + 1; $colour = $combine_array[$name]; $colour = trim($colour); $color = ${$colour}; for ($j = 0; $j < count($rval) - 1; $j++) { $ful = $rval[$j]; $dt_val = $dt_array[$d_inc]; $dt_val1 = $dt_array[$d_inc + 1]; //echo $d_inc.($d_inc + 1)."<br>"; //echo "$dt_val $dt_val1<br>"; $y1 = $starty_val - 78 * $ful; $x1 = $startx_val + $interval * $dt_val; //cal using No of Days $x2 = $startx_val + $interval * $dt_val1; $ful2 = $rval[$j + 1]; $y2 = $starty_val - 78 * $ful2; ImageLine($image, $x1, $y1, $x2, $y2, $color); //ImageString($image, $labelfont1,80,$inc,"$ful" ,$col); $inc = $inc + 10; $x1 = $x2; //$y1 = $y2; $nor = 1; $ct = count($rval) - 1; if ($j == $ct - 1) { $nor = $nor + 1; } $d_inc = $d_inc + $nor; } //j loop ImageString($image, $labelfont1, 130, $n_inc, "{$colour} {$name} {$error_msg['cAvg']}={$avg}", $color); $n_inc += 10; } // i loop if ($overall != "") { ImageString($image, $labelfont1, 130, 250, "{$error_msg['cOverallavg']} = {$overall}", $over); } header("Content-type: image/png"); Imagepng($image); ImageDestroy($image); }
function MakeCircularGraph($im, $Cx, $Cy, $radius, $arr, $column, $linecolor, $name = "wonsusa", $option = 1) { //원 그리기 ImageArc($im, $Cx, $Cy, $radius * 2, $radius * 2, 0, 360, $linecolor); $count_arr = count($arr); for ($i = 0; $i < $count_arr; $i++) { $total += $arr[$i][$column]; } //초기화. $white = ImageColorAllocate($im, 255, 255, 255); $black = ImageColorAllocate($im, 0, 0, 0); $angle = 0; $offset = 0; $b_x = $Cx; $b_y = $Cy - $radius; $real_count = 0; for ($i = 0; $i < $count_arr; $i++) { if ($arr[$i][$column] > 0) { //퍼센티지 구하기. $arr[$i][pctg] = round($arr[$i][$column] / $total * 100, 2); //p점의 앵글 구하기. $arr[$i][p_angle] = round(360 * ($arr[$i][$column] / $total), 2); // 호 그리기. //ImageArc($im, $Cx, $Cy, $radius * 2, $radius * 2, $angle, $arr[$i][p_angle], $linecolor); //$angle += $arr[$i][p_angle]; //이상은 화면에 글자로 표시해줄것들을 구한것이고 //이하는 실제 그림을 그리기 위한 기울기, 좌표 등을 구한다. $theta = $angle + $arr[$i][p_angle] + 90; // y축에서 시작하기 때문에. $arr[$i][p_x] = round(-1 * ($radius * cos(2 * pi() * $theta / 360)) + $Cx); $arr[$i][p_y] = round(-1 * ($radius * sin(2 * pi() * $theta / 360)) + $Cy); // 해당 영역 안에 대표점을 찾아서 색을 채워야 한다. // 대표점 x : cos(각도/2) * 길이, y : sin(각도/2) * 길이 이렇게 구해준다. // -1 을 곱해준 이유는 시계방향으로 그리기 위하여. $theta = $angle + $arr[$i][p_angle] / 2 + 90; // y축에서 시작하기 때문에. $arr[$i][typical_x] = round(-1 * ($radius * 4 / 5 * cos(2 * pi() * $theta / 360)) + $Cx); $arr[$i][typical_y] = round(-1 * ($radius * 4 / 5 * sin(2 * pi() * $theta / 360)) + $Cy); // 정리. $offset += $arr[$i][$column]; //이전점 저장. $b_x = $arr[$i][p_x]; $b_y = $arr[$i][p_y]; $angle += $arr[$i][p_angle]; // 라인 그리기. // 라인은 원점 (250,250) 에서 구한점까지의 거리이다. Imageline($im, $Cx, $Cy, $arr[$i][p_x], $arr[$i][p_y], $linecolor); //화면에 나온것이 몇개가 되는것인지. $real_count++; } // end of if.. } //각 원수사별 색을 설명해 줘야 한다. if ($option == 1) { // 정보를 보여주기 전에 텍스트가 차지 하는 비율을 계산하여 알맞은 박스를 그려준다. // $real_count => 줄수이다. $text_size = 9; //텍스트 사이즈. // 한글 지원 되는 폰트 종류 세가지 : kyunko.TTF,HMFMOLD.TTF,H2PORL.TTF, $fontfile = "/home/khai/aim_manage/public_html/libs/font/H2PORL.TTF"; //폰트 $max_xsize = 0; //박스의 너비 $max_ysize = 0; //박스의 높이 for ($i = 0; $i < $count_arr; $i++) { //박스를 그려서 그 안에 설명을 넣어주려 했는데 박스를 안그리는게 더 이쁘다. $arr_text_box = ImageTTFBBox($text_size, 0, $fontfile, $arr[$i][$name] . "(" . $arr_work[$i][pctg] . "%)"); $width = abs($arr_text_box[2] - $arr_text_box[0]); //가장긴것을 찾는다. $max_xsize = $max_xsize > $width ? $max_xsize : $width; } } else { $max_xsize = 150; } $max_ysize = $real_count * 18; //사각 박스의 좌측 상단 좌표 = ($Cx + $radius + 20, $Cx - $radius) //사각 박스의 우측 하단 좌표 = ($Cx + $radius + 20 + $max_xsize + 5, $Cx - $radius + $max_ysize) // 색깔 설명을위한 사각 박스 그리기 // 박스는 생략한다. //ImageRectangle($im, $Cx + $radius + 20, $Cx - $radius, $Cx + $radius + 20 + $max_xsize + 5, $Cx - $radius + $max_ysize, $black); //색깔 채우기. $carry = 0; for ($i = 0; $i < $count_arr; $i++) { if ($arr[$i][$column] > 0) { //대표점의 색깔 채우기. ImageFill($im, $arr[$i][typical_x], $arr[$i][typical_y], $arr[$i][color_identifier]); //이 색깔 설명해 주기. //네모 그리기 $box_P0x = $Cx + $radius + 20 + 5; //x 좌표 : 사각 박스의 x좌표에 5더하기 $box_P0y = $Cy - $radius + $carry * (int) $max_ysize / $real_count + 5; //y 좌표 $box_size = 5; //박스의 크기 ImageRectangle($im, $box_P0x, $box_P0y, $box_P0x + $box_size, $box_P0y + $box_size, $white); //네모안에 색깔 채우기 ImageFilledRectangle($im, $box_P0x, $box_P0y, $box_P0x + $box_size, $box_P0y + $box_size, $arr[$i][color_identifier]); //바로 옆에 데이터 써주기 // ImageTTFText 에서는 글자의위치가 왼쪽하단이 기준이다. // 5, 11을 더 더해주기로 했다. if ($option == 1) { $text_Px = $Cx + $radius + 25 + $box_size + 5; //텍스트의 x좌표 : 색깔 채운 네모에서 5만큼 더 옆으로. $text_Py = $Cy - $radius + $carry * (int) $max_ysize / $real_count + 1 + 11; //y 좌표 ImageTTFText($im, $text_size, 0, $text_Px, $text_Py, $black, $fontfile, str2uni($arr[$i][$name]) . "(" . $arr[$i][pctg] . "%)"); } else { $text_Px = $Cx + $radius + 25 + $box_size + 5; $text_Py = $Cy - $radius + $carry * (int) $max_ysize / $real_count + 1; //y 좌표 //비트맵 폰트 형식으로 그리기. ImageString($im, 2, $text_Px, $text_Py, $arr[$i][$name] . "(" . $arr[$i][pctg] . "%)", $black); } $carry++; } } }
//echo floor($i*$gridscore)."<br/>Q".$result[floor($i*$gridscore)]."<br/>"; Imageline($im, $lastx, $lasty, $piclength - $left - $i * $gridlength, $y + $down - $result[floor($i * $gridscore)] * $gridy, $line_color); $lastx = $piclength - $left - $i * $gridlength; $lasty = $y + $down - $result[floor($i * $gridscore)] * $gridy; } foreach ($result2 as $key => $value) { if ($value != 0) { ImageFilledRectangle($im, $piclength - $left - $key / $gridscore * $gridlength + $cut / $gridscore * $gridlength, $y + 1 + $down, $piclength - $left - $key / $gridscore * $gridlength + $cut / $gridscore * $gridlength + $value * $gridlength / $gridscore, $y + 25 + $down, $numColor); ImageString($im, 2, $piclength - $left - $key / $gridscore * $gridlength + $cut / $gridscore * $gridlength + $value * $gridlength / $gridscore * 0.65, $y + 30 + $down, -floor($key) + $value + $cut, $line_color); ImageString($im, 2, $piclength - $left - $key / $gridscore * $gridlength + $cut / $gridscore * $gridlength + $value * $gridlength / $gridscore * 0.2, $y + 40 + $down, "region" . $region[$key], $line_color); ImageString($im, 2, $piclength - $left - $key / $gridscore * $gridlength + $cut / $gridscore * $gridlength + $value * $gridlength / $gridscore * 0.05, $y + 30 + $down, -floor($key) + $cut, $line_color); } } /*for($i=$ScaleLen-$leff; $i>0; $i-=$GridUnit) { if($i%($GridUnit*$LabelUnit)==0) { Imageline($im,$x+$i,$y-7,$x+$i,$y,$line_color); ImageString($im,2,$x+$i,$y-18,(int)(($i*$MinLabel*$Unit)/($GridUnit*$LabelUnit)),$numColor); } else { Imageline($im,$x+$i,$y-5,$x+$i,$y,$line_color); } } */ Imageline($im, $x, $y - $picheight + $down, $x, $y + $down, $line_color); for ($i = 0; $i < $ymax + 5; $i++) { if ($i % 5 == 0) { ImageString($im, 2, $x - 20, $y + $down - $i * $gridy - $gridy, $i, $numColor); Imageline($im, $x - 5, $y + $down - $i * $gridy, $x, $y + $down - $i * $gridy, $line_color); } } //header ("Content-type: image/png"); ImagePng($im); ImageDestroy($im);
function display($db_object, $common, $user_id, $default, $error_msg, $learning, $get_var) { $width = 345; $height = 300; $labelfont = 2; $labelfont1 = 1; $labeltitlefont = '3'; $image = ImageCreate($width, $height); while (list($kk, $vv) = @each($get_var)) { ${$kk} = $vv; } $bgcolor = ImageColorAllocate($image, 0xffffff, 0xffffff, 0xffffff); $border = ImageColorAllocate($image, 0, 0, 0); $blue = imagecolorallocate($image, 0x33, 0x0, 0xff); $red = imagecolorallocate($image, 0xff, 0x0, 0x0); $green = imagecolorallocate($image, 0x33, 0xcc, 0x0); $rose = imagecolorallocate($image, 0xff, 0x33, 0xff); $color1 = $red; $color2 = $blue; $color3 = $green; $color4 = $rose; /* to check $date_array = "2003-12-01,2003-12-02,2003-12-02,2003-12-12:2003-12-12:2003-12-20,2003-12-22:2003-12-23:2003-12-19"; $fulfilled_array = "0.00,0.00,30.00,0.00:20.00:50.00,80.00:55.00:60.00"; $ratername = "p,anish,naren,mano,jacob"; $avgval = "6.00,20.00,50.00,45.00,75.00"; $fromdate = "2003-12-01"; $todate ="2003-12-25";*/ $fdate = $fromdate; $tdate = $todate; $mgfulfill = @split(":", $fulfilled_array); $mgdate = @split(":", $date_array); $mgname = @split(",", $ratername); $mgavg = @split(",", $avgval); $to = split("-", $tdate); $from = split("-", $fdate); $dt1 = mktime(0, 0, 0, $to[1], $to[2], $to[0]); $dt2 = mktime(0, 0, 0, $from[1], $from[2], $from[0]); $dt3 = $dt1 - $dt2; $daydiff = $dt3 / 60 / 60 / 24; $days = $error_msg['cDays'] . " {$fdate} " . $error_msg['cTo'] . " {$tdate} "; ImageRectangle($image, 40, 24, 305, 180, $border); ImageString($image, $labelfont, 15, 19, "100%", $border); ImageString($image, $labelfont, 20, 58, "75%", $border); ImageString($image, $labelfont, 20, 97, "50%", $border); ImageString($image, $labelfont, 20, 136, "25%", $border); ImageString($image, $labelfont, 20, 175, "0%", $border); ImageString($image, $labeltitlefont, 70, 182, "{$days}", $border); ImageStringUp($image, $labeltitlefont, 5, 140, $error_msg['cResults'], $border); Imageline($image, 40, 180, 305, 24, $border); $im_dates = split("-", $fdate); $n_inc = 200; /*$p1 = "33"; $p2 = "CC"; $p3 = "CC"; $p1 = hexdec($p1); $p2 = hexdec($p2); $p3 = hexdec($p3);*/ for ($e = 0; $e < count($mgname); $e++) { $p1 = rand(0, 200); $p2 = rand(30, 250); $p3 = rand(100, 250); $name = $mgname[$e]; $fulfilled_array = @split(",", $mgfulfill[$e]); $date_array = @split(",", $mgdate[$e]); $pl = $e + 1; $col = "color" . $pl; $x1 = 40; $y1 = 180; $startx_val = $x1; $starty_val = $y1; //echo "p1=$p1 p2=$p2 p3=$p3<br>"; //echo "hp1=$p1 hp2=$p2 hp3=$p3<br>"; $color = imagecolorallocate($image, $p1, $p2, $p3); $min = 38; $max = 305; $tot = $max - $min; $count = $daydiff; $interval = @($tot / $count); $interval = sprintf("%01.0f", $interval); //ImageString($image, $labelfont, 15,40, "$fulfilled_array", $border); for ($j = 0; $j <= $count; $j++) { if ($min <= $max) { ImageString($image, $labelfont1, $min, 176, "|", $border); } $min = $min + $interval; } $dt_array = array(); $inc = 40; //to calculate the x2 value $odd = array("01", "03", "05", "07", "08", "10", "12"); //31 days $even = array("04", "06", "09", "11"); //30 days for ($d = 0; $d < count($date_array); $d++) { $start_date = $im_dates[2]; $ar = $date_array[$d]; $im_da = split("-", $ar); $dte = $im_da[2]; $m = $im_da[1]; for ($c = 0; $c <= $daydiff; $c++) { if ($dte == $start_date) { $dt_array[] = $c; } $start_date = $start_date + 1; if (in_array($m, $odd)) { if ($start_date == 32) { $start_date = 1; $m = $m + 1; if ($m == 13) { $m = 1; } } } elseif (in_array($m, $even)) { if ($start_date == 31) { $start_date = 1; $m = $m + 1; if ($m == 13) { $m = 1; } } } else { if ($start_date == 29) { $start_date = 1; $m = $m + 1; } } } } for ($i = 0; $i < count($fulfilled_array); $i++) { $ful = $fulfilled_array[$i]; $dt_val = $dt_array[$i]; $x2 = $startx_val + $interval * $dt_val; //cal using No of Days $div = $ful / 25; $y2 = $starty_val - 39 * $div; ImageLine($image, $x1, $y1, $x2, $y2, $color); //imagefill($image,$x1,$y1,$color); //imagefill($image,$x2,$y2,$color); //echo "x1 = $x1 : y1 = $y1 x2 = $x2 y2 = $y2<br>"; $x1 = $x2; $y1 = $y2; } $avg = $mgavg[$e]; ImageString($image, $labelfont1, 130, $n_inc, "{$name} {$error_msg['cAvg']}={$avg}", $color); $n_inc += 10; } //e loop //imagefill($image,59,123,$green); header("Content-type: image/png"); Imagepng($image); ImageDestroy($image); }
/** * Created by PhpStorm. * User: zhuangshaoxiong * Date: 2015/12/3 * Time: 20:19 */ $string = "abcdefghijklmnopqrstuvwxyz0123456789"; $str = ""; for ($i = 0; $i < 4; $i++) { $pos = rand(0, 35); $str .= $string[$pos]; } session_start(); $_SESSION['checknode'] = $str; $img_handle = Imagecreate(100, 20); $back_color = ImageColorAllocate($img_handle, 255, 255, 255); $txt_color = ImageColorAllocate($img_handle, 0, 0, 0); echo ddddd; 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, 10, 0, $str, $txt_color); ob_clean(); header("Content-Type: image/png;"); Imagepng($img_handle);