Beispiel #1
0
function FilledArc(&$im, $CenterX, $CenterY, $DiameterX, $DiameterY, $Start, $End, $line_color, $fill_color = 'none')
{
    if (gd_version() >= 2.0) {
        if ($fill_color != 'none') {
            // fill
            ImageFilledArc($im, $CenterX, $CenterY, $DiameterX, $DiameterY, $Start, $End, $fill_color, IMG_ARC_PIE);
        }
        // outline
        ImageFilledArc($im, $CenterX, $CenterY, $DiameterX, $DiameterY, $Start, $End, $line_color, IMG_ARC_EDGED | IMG_ARC_NOFILL | IMG_ARC_PIE);
    } else {
        // cbriou@orange-art.fr
        // To draw the arc
        ImageArc($im, $CenterX, $CenterY, $DiameterX, $DiameterY, $Start, $End, $line_color);
        // To close the arc with 2 lines between the center and the 2 limits of the arc
        $x = $CenterX + cos(deg2rad($Start)) * ($DiameterX / 2);
        $y = $CenterY + sin(deg2rad($Start)) * ($DiameterY / 2);
        ImageLine($im, $x, $y, $CenterX, $CenterY, $line_color);
        $x = $CenterX + cos(deg2rad($End)) * ($DiameterX / 2);
        $y = $CenterY + sin(deg2rad($End)) * ($DiameterY / 2);
        ImageLine($im, $x, $y, $CenterX, $CenterY, $line_color);
        if ($fill_color != 'none') {
            if ($End - $Start > 0.5) {
                // ImageFillToBorder() will flood the wrong parts of the image if the slice is too small
                // thanks Jami Lowery <*****@*****.**> for pointing out the problem
                // To fill the arc, the starting point is a point in the middle of the closed space
                $x = $CenterX + cos(deg2rad(($Start + $End) / 2)) * ($DiameterX / 4);
                $y = $CenterY + sin(deg2rad(($Start + $End) / 2)) * ($DiameterY / 4);
                ImageFillToBorder($im, $x, $y, $line_color, $fill_color);
            }
        }
    }
}
Beispiel #2
0
 function create($varDesc, $varValues)
 {
     Header("Content-type: image/png");
     $image = ImageCreate($this->imageWidth, $this->imageHeight);
     $bgcolor = ImageColorAllocate($image, $this->bgR, $this->bgG, $this->bgB);
     $white = ImageColorAllocate($image, 255, 255, 255);
     $black = ImageColorAllocate($image, 0, 0, 0);
     ImageFill($image, 0, 0, $bgcolor);
     $num = 0;
     foreach ($varDesc as $v) {
         $r = rand(0, 255);
         $g = rand(0, 255);
         $b = rand(0, 255);
         $sliceColors[$num] = ImageColorAllocate($image, $r, $g, $b);
         $num++;
     }
     // now $num has the number of elements
     // draw the box
     ImageLine($image, 0, 0, $this->imageWidth - 1, 0, $black);
     ImageLine($image, $this->imageWidth - 1, 0, $this->imageWidth - 1, $this->imageHeight - 1, $black);
     ImageLine($image, $this->imageWidth - 1, $this->imageHeight - 1, 0, $this->imageHeight - 1, $black);
     ImageLine($image, 0, $this->imageHeight - 1, 0, 0, $black);
     $total = 0;
     for ($x = 0; $x < $num; $x++) {
         $total += $varValues[$x];
     }
     // convert each slice into corresponding percentage of 360-degree circle
     for ($x = 0; $x < $num; $x++) {
         $angles[$x] = $varValues[$x] / $total * 360;
     }
     for ($x = 0; $x < $num; $x++) {
         // calculate and draw arc corresponding to each slice
         ImageArc($image, $this->imageWidth / 4, $this->imageHeight / 2, $this->imageWidth / 3, $this->imageHeight / 3, $angle, $angle + $angles[$x], $sliceColors[$x]);
         $angle = $angle + $angles[$x];
         $x1 = round($this->imageWidth / 4 + $this->imageWidth / 3 * cos($angle * pi() / 180) / 2);
         $y1 = round($this->imageHeight / 2 + $this->imageHeight / 3 * sin($angle * pi() / 180) / 2);
         // demarcate slice with another line
         ImageLine($image, $this->imageWidth / 4, $this->imageHeight / 2, $x1, $y1, $sliceColors[$x]);
     }
     // fill in the arcs
     $angle = 0;
     for ($x = 0; $x < $num; $x++) {
         $x1 = round($this->imageWidth / 4 + $this->imageWidth / 3 * cos(($angle + $angles[$x] / 2) * pi() / 180) / 4);
         $y1 = round($this->imageHeight / 2 + $this->imageHeight / 3 * sin(($angle + $angles[$x] / 2) * pi() / 180) / 4);
         ImageFill($image, $x1, $y1, $sliceColors[$x]);
         $angle = $angle + $angles[$x];
     }
     // put the desc strings
     ImageString($image, 5, $this->imageWidth / 2, 60, "Legend", $black);
     for ($x = 0; $x < $num; $x++) {
         $fl = sprintf("%.2f", $varValues[$x] * 100 / $total);
         $str = $varDesc[$x] . " (" . $fl . "%)";
         ImageString($image, 3, $this->imageWidth / 2, ($x + 5) * 20, $str, $sliceColors[$x]);
     }
     // put the title
     ImageString($image, 5, 20, 20, $this->title, $black);
     ImagePng($image);
     ImageDestroy($image);
 }
 function G($width = 100, $heiht = 37)
 {
     mt_srand((double) microtime() * 1000000);
     if ($this->number) {
         $hash = sprintf('%0' . $this->length . 'd', mt_rand(0, pow(10, $this->length) - 1));
     } else {
         $hash = '';
         $chars = 'ABCDEQRSTUVWXYZ23456FGHIJKLMNP789';
         $max = strlen($chars) - 1;
         for ($i = 0; $i < $this->length; $i++) {
             $hash .= $chars[mt_rand(0, $max)];
         }
     }
     $this->session->set_userdata('validecode', strtolower($hash));
     $im = imagecreate($width, $heiht);
     $backgroundcolor = imagecolorallocate($im, 255, 255, 255);
     $numorder = array(1, 2, 3, 4);
     shuffle($numorder);
     $numorder = array_flip($numorder);
     for ($i = 1; $i <= 4; $i++) {
         $x = $numorder[$i] * 20 + mt_rand(0, 4) - 2;
         $y = mt_rand(2, 12);
         $text_color = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 128), mt_rand(50, 255));
         imagechar($im, 5, $x + 12, $y, $hash[$numorder[$i]], $text_color);
     }
     $linenums = mt_rand(10, 32);
     for ($i = 0; $i < 4; $i++) {
         $color1 = ImageColorAllocate($im, mt_rand(100, 255), mt_rand(100, 255), mt_rand(100, 255));
         ImageArc($im, mt_rand(-5, $width), mt_rand(-5, $heiht), mt_rand(30, $width), mt_rand(30, $heiht), 55, 44, $color1);
     }
     for ($i = 0; $i <= $linenums; $i++) {
         $linecolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         $linex = mt_rand(0, $width - 2);
         $liney = mt_rand(0, $heiht - 2);
         imageline($im, $linex, $liney, $linex + mt_rand(0, 4) - 2, $liney + mt_rand(0, 4) - 2, $linecolor);
     }
     for ($i = 0; $i <= $width - 2; $i++) {
         $pointcolor = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 255), mt_rand(50, 255));
         imagesetpixel($im, mt_rand(0, $width - 2), mt_rand(0, $heiht - 2), $pointcolor);
     }
     $bordercolor = imagecolorallocate($im, 150, 150, 150);
     imagerectangle($im, 0, 0, $width - 2, $heiht - 2, $bordercolor);
     header('Content-type: image/png');
     imagepng($im);
     imagedestroy($im);
 }
function FilledArc(&$im, $CenterX, $CenterY, $DiameterX, $DiameterY, $Start, $End, $line_color, $fill_color='none',$key='') 
	{
	ImageArc($im, $CenterX, $CenterY, $DiameterX, $DiameterY, $Start, $End, $line_color);
	// To close the arc with 2 lines between the center and the 2 limits of the arc 
	$x = $CenterX + (cos(deg2rad($Start)) * ($DiameterX / 2)); 
	$y = $CenterY + (sin(deg2rad($Start)) * ($DiameterY / 2)); 
	ImageLine($im, $x, $y, $CenterX, $CenterY, $line_color); 
	$x = $CenterX + (cos(deg2rad($End)) * ($DiameterX / 2)); 
	$y = $CenterY + (sin(deg2rad($End)) * ($DiameterY / 2)); 
	ImageLine($im, $x, $y, $CenterX, $CenterY, $line_color); 
	// To fill the arc, the starting point is a point in the middle of the closed space 
	$x = $CenterX + (cos(deg2rad(($Start + $End) / 2)) * ($DiameterX / 4)); 
	$y = $CenterY + (sin(deg2rad(($Start + $End) / 2)) * ($DiameterY / 4)); 
	ImageFillToBorder($im, $x, $y, $line_color, $fill_color);
	
	// Ainda faltam vários ajustes para escrita do label na vertical... Anderson Peterle => 08/08/2007
	if ($key)
		imagestringup($im,2,$x,$y,$key,$x);
	}
Beispiel #5
0
$black = ImageColorAllocate($im, 0, 0, 0);
$color[0] = ImageColorAllocate($im, 255, 204, 102); //оранжевый
$color[1] = ImageColorAllocate($im, 51, 204, 0); // «еленый
$color[2] = ImageColorAllocate($im, 0, 102, 152); // темно синий
$color[3] = ImageColorAllocate($im, 255, 0, 0); // красный
$color[4] = ImageColorAllocate($im, 255, 255, 255); // белый
ImageColorTransparent($im, $white);

$sum = $vote1 + $vote2 + $vote3 + $vote4 + $vote5;
$vote1 = ($vote1/$sum)*360;
$vote2 = (($vote2/$sum)*360) + $vote1;
$vote3 = ($vote3/$sum)*360 + $vote2;
$vote4 = ($vote4/$sum)*360 + $vote3;
$vote5 = ($vote5/$sum)*360 + $vote4;

ImageArc($im, $xsize/2, $ysize/2, $xsize, $ysize, 0, 360, $black);


function linealfa ($alfa, $alfaold, $numcolor)
{
	global $xsize, $ysize, $im, $black, $color;
	$gradus = ($alfa + $alfaold)/2;
	$alfa = ($alfa * pi())/180;
	$x = $xsize/2 + ($xsize/2) * sin($alfa);
	$y = $ysize/2 - ($xsize/2) * cos($alfa);
	ImageLine($im, $xsize/2, $ysize/2, $x, $y, $black);

	$gradus = ($gradus * pi())/180;
	$x = $xsize/2 + ($xsize/3) * sin($gradus);
	$y = $ysize/2 - ($ysize/3) * cos($gradus);
	if ($gradus!=0) ImageFill($im, $x, $y, $color[$numcolor]);
Beispiel #6
0
 function draw_slice($x, $y, $from, $to, $color)
 {
     # Awful Kludge!!!
     if ($to > 360) {
         $to = 360;
     }
     ImageArc($this->im, $this->center_x, $this->center_y, $this->diameter, $this->diameter, $from, $to, $color);
     /* First line */
     $axy2 = $this->get_xy_factors($from);
     $ax2 = floor($this->center_x + $axy2[0] * ($this->diameter / 2));
     $ay2 = floor($this->center_y + $axy2[1] * ($this->diameter / 2));
     ImageLine($this->im, $this->center_x, $this->center_y, $ax2, $ay2, $color);
     /* Second line */
     $bxy2 = $this->get_xy_factors($to);
     $bx2 = ceil($this->center_x + $bxy2[0] * ($this->diameter / 2));
     $by2 = ceil($this->center_y + $bxy2[1] * ($this->diameter / 2));
     ImageLine($this->im, $this->center_x, $this->center_y, $bx2, $by2, $color);
     /* decide where to start filling, then fill */
     $xy2 = $this->get_xy_factors(($to - $from) / 2 + $from);
     $x2 = floor($this->center_x + $xy2[0] * ($this->diameter / 3));
     $y2 = floor($this->center_y + $xy2[1] * ($this->diameter / 3));
     ImageFillToBorder($this->im, $x2, $y2, $color, $color);
 }
Beispiel #7
0
    } else {
        if ($min % 5 == 0) {
            $len = $radius / 10;
        } else {
            $len = $radius / 25;
        }
    }
    $ang = 2 * M_PI * $min / 60;
    $x1 = sin($ang) * ($radius - $len) + $radius;
    $y1 = cos($ang) * ($radius - $len) + $radius;
    $x2 = 1 * sin($ang) * $radius;
    $y2 = 1 * cos($ang) * $radius;
    ImageLine($img, $x1, $y1, $x2, $y2, $color_black);
}
list($hour, $min, $sec) = preg_split("/-/", Date("h-i-s", time() - 3600));
$hour = $hour % 12;
$xs = intval(cos($sec * M_PI / 30 - M_PI / 2) * 0.75 * $radius + $radius);
$ys = intval(sin($sec * M_PI / 30 - M_PI / 2) * 0.75 * $radius + $radius);
$xm = intval(cos($min * M_PI / 30 - M_PI / 2) * 0.65 * $radius + $radius);
$ym = intval(sin($min * M_PI / 30 - M_PI / 2) * 0.65 * $radius + $radius);
$xh = intval(cos($hour * 5 * M_PI / 30 - M_PI / 2) * 0.5 * $radius + $radius);
$yh = intval(sin($hour * 5 * M_PI / 30 - M_PI / 2) * 0.5 * $radius + $radius);
ImageLine($img, $radius, $radius, $xs, $ys, $color_grey);
ImageLine($img, $radius, $radius - 1, $xm, $ym, $color_blue);
ImageLine($img, $radius - 1, $radius, $xm, $ym, $color_blue);
ImageLine($img, $radius, $radius - 1, $xh, $yh, $color_blue);
ImageLine($img, $radius - 1, $radius, $xh, $yh, $color_blue);
ImageArc($img, $radius, $radius, $radius / 8, $radius / 8, 0, 360, $color_red);
ImageFillToBorder($img, $radius, $radius, $color_red, $color_red);
ImageGif($img);
ImageDestroy($img);
Beispiel #8
0
 function DrawPie()
 {
     $width = $this->chart_area[2] - $this->chart_area[0];
     $height = $this->chart_area[3] - $this->chart_area[1];
     list($r, $g, $b) = ColorSet('black');
     $black = ImageColorAllocate($this->img, $r, $g, $b);
     $xpos = $this->chart_area[0] + $width / 2;
     $ypos = $this->chart_area[1] + $height / 2;
     $durchmesser = min($width, $height) * 0.97;
     $radius = $durchmesser / 2;
     ImageArc($this->img, $xpos, $ypos, $durchmesser, $durchmesser, 0, 360, $black);
     //ImageFillToBorder($this->img, $xpos, $ypos, $black, $black);
     $helpcol = ImageColorAllocate($this->img, 12, 12, 12);
     ImageArc($this->img, $xpos, $ypos, $durchmesser, $durchmesser, 0, 360, $helpcol);
     $i = 0;
     $total = 0;
     foreach ($this->data_values as $row) {
         $colcount = 0;
         $i = 0;
         foreach ($row as $v) {
             if ($v != $row[0]) {
                 // sum up
                 $sumarr[$i] += $v;
                 $total += $v;
             }
             $i++;
         }
     }
     $colcount = 0;
     $kreis_start = $this->arc_start;
     $umfang = $radius * 2 * pi();
     $winkel = $kreis_start;
     foreach ($sumarr as $val) {
         if ($colcount >= count($this->bar_color)) {
             $colcount = 0;
         }
         $prozent = number_format($val / $total * 100, 1, ',', '.') . '%';
         $val = round($val / $total * 360);
         $winkel += $val;
         $farbwinkel = $winkel - $val / 2;
         $val += $kreis_start;
         $barcol = $this->bar_color[$colcount];
         list($r, $g, $b) = ColorSet($barcol);
         $barcol = ImageColorAllocate($this->img, $r, $g, $b);
         //ImageArc($this->img, $xpos, $ypos, $durchmesser, $durchmesser, $kreis_start, $val, $black);
         ImageArc($this->img, $xpos, $ypos, $durchmesser, $durchmesser, 0, 3560, $black);
         $out_x = $radius * cos(deg2rad($winkel));
         $out_y = -$radius * sin(deg2rad($winkel));
         $halbradius = $radius / 2;
         $farb_x = $xpos + $halbradius * cos(deg2rad($farbwinkel));
         $farb_y = $ypos + -$halbradius * sin(deg2rad($farbwinkel));
         $out_x = $xpos + $out_x;
         $out_y = $ypos + $out_y;
         ImageLine($this->img, $xpos, $ypos, $out_x, $out_y, $black);
         //ImageLine($this->img, $xpos, $ypos, $farb_x, $farb_y, $black);
         ImageFillToBorder($this->img, $farb_x, $farb_y, $black, $barcol);
         ImageTTFText($this->img, $this->axis_font_size, 0, $farb_x, $farb_y, $black, $this->font, $prozent);
         $kreis_start = $val;
         $colcount++;
     }
     //ImageArc($this->img, $xpos, $ypos, $durchmesser, $durchmesser, 0, 360, $black);
 }
Beispiel #9
0
            $cas_textcolor = $cas_textcolorchoice[$cas_rand];
            break;
        default:
            $cas_textcolor = array(255, 255, 255);
            break;
    }
}
// Start building the image
$cas_image = @imagecreate($cas_imgwidth, $cas_imgheight) or die("Cannot Initialize new GD image stream");
$cas_bgcolor = imagecolorallocate($cas_image, $cas_bgcolor[0], $cas_bgcolor[1], $cas_bgcolor[2]);
$cas_fontcolor = imagecolorallocate($cas_image, $cas_textcolor[0], $cas_textcolor[1], $cas_textcolor[2]);
// Add noice lines
if ($cas_noise_line) {
    for ($i = 0; $i < $wordcount; $i++) {
        $color_line = ImageColorAllocate($cas_image, mt_rand(155, 255), mt_rand(155, 255), mt_rand(155, 255));
        ImageArc($cas_image, mt_rand(-5, $cas_imgwidth), mt_rand(-5, $cas_imgheight), mt_rand(20, 300), mt_rand(20, 200), 55, 44, $color_line);
    }
}
// Add noice points
if ($cas_noise_point) {
    for ($i = 0; $i < $wordcount * 50; $i++) {
        $color_point = ImageColorAllocate($cas_image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
        ImageSetPixel($cas_image, mt_rand(0, $cas_imgwidth), mt_rand(0, $cas_imgheight), $color_point);
    }
}
// Check for freetype lib, if not found default to ugly built in capability using imagechar (Lee's mod)
// Also check that the chosen TrueType font is available
if (function_exists('imagettftext') && file_exists($cas_font)) {
    $cas_angle = 3;
    // Degrees to tilt the text
    $cas_offset = 5;
Beispiel #10
0
function ImageRoundEdges($image, $size, $args = array()){
	if (!is_numeric($size)){
		throw new Exception("Not a valid size: " . $size);
	}
	
	$width = ImageSX($image);
	$height = ImageSY($image);
	
	if ($args["border"]){
		$bordercolor = ImageHTMLColor($image, $args["border"]);
		$oldimage = $image;
		$image = ImageCreateTrueColor($width, $height);
		ImageFilledRectangle($image, 0, 0, $width, $height, $bordercolor);
		ImageCopyResized($image, $oldimage, 1, 1, 0, 0, $width - 2, $height - 2, $width, $height);
	}else{
		$oldimage = $image;
		$image = ImageCreateTrueColor($width, $height);
		ImageCopyResized($image, $oldimage, 0, 0, 0, 0, $width, $height, $width, $height);
	}
	
	$transp = ImageColorTransparent($image);
	if (!$transp or $transp == -1){
		if ($args["htmltranscolor"]){
			$transp = ImageHTMLColor($image, $args["htmltranscolor"]);
		}else{
			$transp = ImageHTMLColor($image, "#d91da2");
		}
	}
	
	for($i = 1; $i < $size / 2; $i++){
		//Upper left corner.
		$center = $i - 2;
		ImageArc($image, $center, $center, $size, $size, 180, 270, $white);
		ImageArc($image, $center - 1, $center, $size, $size, 180, 270, $white);
		
		ImageArc($image, $center, $center, $size, $size, 180, 270, $transp);
		ImageArc($image, $center - 1, $center, $size, $size, 180, 270, $transp);
		
		
		//Upper right corner.
		$left = $width - $i + 2;
		$top = $i - 2;
		
		ImageArc($image, $left, $top, $size, $size, 270, 360, $transp);
		ImageArc($image, $left, $top - 1, $size, $size, 270, 360, $transp);
		
		
		//Lower left corner.
		$left = $i - 2;
		$top = $height - $i + 2;
		
		ImageArc($image, $left, $top, $size, $size, 90, 180, $transp);
		ImageArc($image, $left, $top - 1, $size, $size, 90, 180, $transp);
		
		
		//Lower right corner.
		$left = $width - $i + 2;
		$top = $height - $i + 2;
		
		ImageArc($image, $left, $top, $size, $size, 0, 90, $transp);
		ImageArc($image, $left, $top - 1, $size, $size, 0, 90, $transp);
	}
	
	if ($args["border"]){
		//Lower right corner.
		$left = $width - $i + 2;
		$top = $height - $i + 2;
		ImageArc($image, $left, $top, $size, $size, 0, 90, $bordercolor);
		
		//Lower left corn
		$left = $i - 2;
		$top = $height - $i + 2;
		ImageArc($image, $left, $top, $size, $size, 90, 180, $bordercolor);
		
		//Upper left corner.
		$center = $i - 2;
		ImageArc($image, $center, $center - 1, $size, $size, 180, 270, $bordercolor);
		
		//Upper right corner.
		$left = $width - $i + 2;
		$top = $i - 2;
		ImageArc($image, $left, $top - 1, $size, $size, 270, 360, $bordercolor);
	}
	
	ImageColorTransparent($image, $transp);
	return $image;
}
Beispiel #11
0
 public function show($callback = NULL)
 {
     Header('Content-type: image/gif');
     /*  
      * 初始化  
      */
     $border = 0;
     //是否要边框 1要:0不要
     $how = $this->num;
     //验证码位数
     $w = $this->width;
     //图片宽度
     $h = $this->height;
     //图片高度
     $fontsize = 5;
     //字体大小
     $alpha = 'abcdefghijkmnopqrstuvwxyz';
     //验证码内容1:字母
     $number = '023456789';
     //验证码内容2:数字
     $randcode = '';
     //验证码字符串初始化
     srand((double) microtime() * 1000000);
     //初始化随机数种子
     $im = ImageCreate($w, $h);
     //创建验证图片
     /*  
      * 绘制基本框架  
      */
     $bgcolor = ImageColorAllocate($im, 255, 255, 255);
     //设置背景颜色
     ImageFill($im, 0, 0, $bgcolor);
     //填充背景色
     if ($border) {
         $black = ImageColorAllocate($im, 0, 0, 0);
         //设置边框颜色
         ImageRectangle($im, 0, 0, $w - 1, $h - 1, $black);
         //绘制边框
     }
     /*  
      * 逐位产生随机字符  
      */
     for ($i = 0; $i < $how; $i++) {
         $alpha_or_number = mt_rand(0, 1);
         //字母还是数字
         $str = $alpha_or_number ? $alpha : $number;
         $which = mt_rand(0, strlen($str) - 1);
         //取哪个字符
         $code = substr($str, $which, 1);
         //取字符
         $j = !$i ? 4 : $j + 15;
         //绘字符位置
         $color3 = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
         //字符随即颜色
         ImageChar($im, $fontsize, $j, 3, $code, $color3);
         //绘字符
         $randcode .= $code;
         //逐位加入验证码字符串
     }
     /*  
      * 添加干扰  
      */
     for ($i = 0; $i < 5; $i++) {
         $color1 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         //干扰线颜色
         ImageArc($im, mt_rand(-5, $w), mt_rand(-5, $h), mt_rand(20, 300), mt_rand(20, 200), 55, 44, $color1);
         //干扰线
     }
     for ($i = 0; $i < $how * 15; $i++) {
         $color2 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         //干扰点颜色
         ImageSetPixel($im, mt_rand(0, $w), mt_rand(0, $h), $color2);
         //干扰点
     }
     //把验证码字符串写入session
     //$_SESSION[$this->name]=$randcode;
     // if (isset($this->output_conf)) {
     //     if (is_array($this->output_conf)) {
     //         $this->output_conf['verify_code'] = $randcode;
     //     } else {
     //         $this->output_conf->verify_code = $randcode;
     //     }
     // }
     // $this->CI->session->set_userdata('verify_code', $randcode);
     if (isset($callback)) {
         $callback($randcode);
     }
     /*绘图结束*/
     Imagegif($im);
     ImageDestroy($im);
     /*绘图结束*/
     return $randcode;
 }
Beispiel #12
0
 private function mixedLine()
 {
     for ($i = 0; $i < 5; $i++) {
         $bordercolor = ImageColorAllocate($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         // 干擾線條顏色
         ImageArc($this->image, mt_rand(-5, $this->width), mt_rand(-5, $this->height), mt_rand(20, 300), mt_rand(20, 200), 55, 44, $bordercolor);
         // 寫入圖片
     }
 }
 function show()
 {
     Header("Content-type: image/gif");
     /*
      * ��ʼ��
      */
     $border = 0;
     //�Ƿ�Ҫ�߿� 1Ҫ:0��Ҫ
     $how = $this->num;
     //��֤��λ��
     $w = $this->width;
     //ͼƬ���
     $h = $this->height;
     //ͼƬ�߶�
     $fontsize = 5;
     //�����С
     $alpha = "abcdefghijkmnopqrstuvwxyz";
     //��֤������1:��ĸ
     $number = "023456789";
     //��֤������2:����
     $randcode = "";
     //��֤���ַ�����ʼ��
     srand((double) microtime() * 1000000);
     //��ʼ�����������
     $im = ImageCreate($w, $h);
     //������֤ͼƬ
     /*
      * ���ƻ������
      */
     $bgcolor = ImageColorAllocate($im, 255, 255, 255);
     //���ñ�����ɫ
     ImageFill($im, 0, 0, $bgcolor);
     //��䱳��ɫ
     if ($border) {
         $black = ImageColorAllocate($im, 0, 0, 0);
         //���ñ߿���ɫ
         ImageRectangle($im, 0, 0, $w - 1, $h - 1, $black);
         //���Ʊ߿�
     }
     /*
      * ��λ��������ַ�
      */
     for ($i = 0; $i < $how; $i++) {
         $alpha_or_number = mt_rand(0, 1);
         //��ĸ��������
         $str = $alpha_or_number ? $alpha : $number;
         $which = mt_rand(0, strlen($str) - 1);
         //ȡ�ĸ��ַ�
         $code = substr($str, $which, 1);
         //ȡ�ַ�
         $j = !$i ? 4 : $j + 15;
         //���ַ�λ��
         $color3 = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
         //�ַ��漴��ɫ
         ImageChar($im, $fontsize, $j, 3, $code, $color3);
         //���ַ�
         $randcode .= $code;
         //��λ������֤���ַ���
     }
     /*
      * ��Ӹ���
      */
     for ($i = 0; $i < 5; $i++) {
         $color1 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         //��������ɫ
         ImageArc($im, mt_rand(-5, $w), mt_rand(-5, $h), mt_rand(20, 300), mt_rand(20, 200), 55, 44, $color1);
         //������
     }
     for ($i = 0; $i < $how * 15; $i++) {
         $color2 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         //���ŵ���ɫ
         ImageSetPixel($im, mt_rand(0, $w), mt_rand(0, $h), $color2);
         //���ŵ�
     }
     //����֤���ַ���д��session
     //$this->session->set_userdata(array($this->name=>$randcode));
     $_SESSION[$this->name] = $randcode;
     /*��ͼ����*/
     Imagegif($im);
     ImageDestroy($im);
     /*��ͼ����*/
 }
            $dybuf = 1;
        } elseif ($dybuf <= 0) {
            //ImageString($im,3,($ox-3),80,$data[$i],$tcolor);
            $tfy = 80;
            $dybuf = 98;
        } else {
            if ($data[$i] < $lo || $data[$i] > $hi) {
                $tcolor = $red;
            } else {
                $tcolor = $black;
            }
            $fontsize = 2;
            $tfx = $ox + 5;
            $tfy = $tabhi - $dybuf - 5;
            $dybuf = $tabhi - $dybuf;
            # invert the values
        }
        ImageArc($im, $ox, $dybuf, 4, 4, 0, 360, $blue);
        if ($ox1 || $oy1) {
            ImageLine($im, $ox1, $oy1, $ox, $dybuf, $blue);
        }
        ImageString($im, $fontsize, $tfx, $tfy, $data[$i], $tcolor);
    }
    $ox1 = $ox;
    $oy1 = $dybuf;
    //$xlb=$ox2;$ylb=$oy2;
    $ox += $tabcols;
}
header('Content-type: image/PNG');
ImagePNG($im);
ImageDestroy($im);
Beispiel #15
0
function create_my_captcha()
{
    Header("Content-type: image/gif");
    /*
     * 初始化
     */
    $border = 0;
    //是否要边框 1要:0不要
    $how = 4;
    //验证码位数
    $w = $how * 15;
    //图片宽度
    $h = 20;
    //图片高度
    $fontsize = 16;
    //字体大小
    $alpha = "abcdefghijkmnpqrstuvwxyzABCDEFGHIGKLMNPQRSTUVWXYZ";
    //验证码内容1:字母
    $number = "23456789";
    //验证码内容2:数字
    $randcode = "";
    //验证码字符串初始化
    srand((double) microtime() * 1000000);
    //初始化随机数种子
    $im = ImageCreate($w, $h);
    //创建验证图片
    /*
     * 绘制基本框架
     */
    $bgcolor = ImageColorAllocate($im, 255, 255, 255);
    //设置背景颜色
    ImageFill($im, 0, 0, $bgcolor);
    //填充背景色
    if ($border) {
        $black = ImageColorAllocate($im, 0, 0, 0);
        //设置边框颜色
        ImageRectangle($im, 0, 0, $w - 1, $h - 1, $black);
        //绘制边框
    }
    /*
     * 逐位产生随机字符
     */
    for ($i = 0; $i < $how; $i++) {
        $alpha_or_number = mt_rand(0, 1);
        //字母还是数字
        $str = $alpha_or_number ? $alpha : $number;
        $which = mt_rand(0, strlen($str) - 1);
        //取哪个字符
        $code = substr($str, $which, 1);
        //取字符
        $j = !$i ? 4 : $j + 15;
        //绘字符位置
        $color3 = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
        //字符随即颜色
        ImageChar($im, $fontsize, $j, 3, $code, $color3);
        //绘字符
        $randcode .= $code;
        //逐位加入验证码字符串
    }
    /*
     * 添加干扰
     */
    for ($i = 0; $i < 2; $i++) {
        $color1 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
        //干扰线颜色
        ImageArc($im, mt_rand(-5, $w), mt_rand(-5, $h), mt_rand(20, 300), mt_rand(20, 200), 55, 44, $color1);
        //干扰线
    }
    for ($i = 0; $i < $how * 7; $i++) {
        $color2 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
        //干扰点颜色
        ImageSetPixel($im, mt_rand(0, $w), mt_rand(0, $h), $color2);
        //干扰点
    }
    //把验证码字符串写入session
    $_SESSION['login_check_number'] = strtoupper($randcode);
    /*绘图结束*/
    Imagegif($im);
    ImageDestroy($im);
    /*绘图结束*/
}
Beispiel #16
0
 function DrawBullet($image, $x, $y, $type, $color)
 {
     switch ($type) {
         case 0:
         case 5:
             for ($i = 0; $i < 8; $i++) {
                 ImageArc($image, $x, $y, $i, $i, 0, 359, $color);
             }
             break;
         case 1:
         case 6:
             ImageFilledRectangle($image, $x - 3, $y - 3, $x + 3, $y + 3, $color);
             break;
         case 2:
         case 7:
             ImageFilledRectangle($image, $x - 1, $y - 4, $x + 1, $y + 4, $color);
             ImageFilledRectangle($image, $x - 4, $y - 1, $x + 4, $y + 1, $color);
             break;
         case 3:
         case 8:
             $points[0] = $x;
             $points[1] = $y - 4;
             $points[2] = $x + 4;
             $points[3] = $y;
             $points[4] = $x;
             $points[5] = $y + 4;
             $points[6] = $x - 4;
             $points[7] = $y;
             ImageFilledPolygon($image, $points, 4, $color);
             break;
         case 4:
         case 9:
             $points[0] = $x;
             $points[1] = $y - 4;
             $points[2] = $x + 4;
             $points[3] = $y + 4;
             $points[4] = $x - 4;
             $points[5] = $y + 4;
             ImageFilledPolygon($image, $points, 3, $color);
             break;
         default:
     }
     return;
 }
Beispiel #17
0
$degCount = 0;
for ($y = 0; $y < $countqw; $y++) {
    if ($sliced[$y] / $sum * 360 > '0') {
        $degrees[$degCount] = $sliced[$y] / $sum * 360;
        $degCount++;
    }
}
Header("Content-Type: image/png");
$im = ImageCreate(550, 300);
$black = ImageColorAllocate($im, 0, 0, 0);
$white = ImageColorAllocate($im, 255, 255, 255);
$hexCode = array("255,153,0", "0,204,153", "204,255,102", "255,102,102", "102,204,255", "204,153,255", "255,0,0", "51,0,255", "255,51,153", "204,0,255", "255,255,51", "51,255,51", "255,102,0", "238,215,232", "218,227,235", "252,255,218", "173,173,90");
ImageFill($im, 0, 0, $white);
ImageLine($im, 150, 150, 225, 150, $black);
for ($z = 0; $z < $countqw; $z++) {
    ImageArc($im, 150, 150, $diameter, $diameter, $last_angle, $last_angle + $degrees[$z], $black);
    $last_angle = $last_angle + $degrees[$z];
    $end_x = round(150 + $radius * cos($last_angle * pi() / 180));
    $end_y = round(150 + $radius * sin($last_angle * pi() / 180));
    ImageLine($im, 150, 150, $end_x, $end_y, $black);
}
$prev_angle = 0;
$pointer = 0;
for ($z = 0; $z < $countqw; $z++) {
    $pointer = $prev_angle + $degrees[$z];
    $this_angle = ($prev_angle + $pointer) / 2;
    $prev_angle = $pointer;
    $end_x = round(150 + $radius * cos($this_angle * pi() / 180));
    $end_y = round(150 + $radius * sin($this_angle * pi() / 180));
    $mid_x = round((150 + $end_x) / 2);
    $mid_y = round((150 + $end_y) / 2);
Beispiel #18
0
 function draw_brush($x, $y, $size, $type, $colour)
 {
     $x = round($x);
     $y = round($y);
     $half = round($size / 2);
     switch ($type) {
         case 'circle':
             ImageArc($this->image, $x, $y, $size, $size, 0, 360, $this->colour[$colour]);
             ImageFillToBorder($this->image, $x, $y, $this->colour[$colour], $this->colour[$colour]);
             break;
         case 'square':
             ImageFilledRectangle($this->image, $x - $half, $y - $half, $x + $half, $y + $half, $this->colour[$colour]);
             break;
         case 'vertical':
             ImageFilledRectangle($this->image, $x, $y - $half, $x + 1, $y + $half, $this->colour[$colour]);
             break;
         case 'horizontal':
             ImageFilledRectangle($this->image, $x - $half, $y, $x + $half, $y + 1, $this->colour[$colour]);
             break;
         case 'slash':
             ImageFilledPolygon($this->image, array($x + $half, $y - $half, $x + $half + 1, $y - $half, $x - $half + 1, $y + $half, $x - $half, $y + $half), 4, $this->colour[$colour]);
             break;
         case 'backslash':
             ImageFilledPolygon($this->image, array($x - $half, $y - $half, $x - $half + 1, $y - $half, $x + $half + 1, $y + $half, $x + $half, $y + $half), 4, $this->colour[$colour]);
             break;
         default:
             @eval($type);
             // user can create own brush script.
     }
 }
Beispiel #19
0
 function DrawData()
 {
     if ($this->set_count == 0) {
         return false;
     }
     // Create scaling
     $ca = $this->ca;
     $this->GetDataLimits($minx, $miny, $maxx, $maxy);
     $range = array($maxx - $minx, $maxy - $miny);
     $ca_range = array($ca[2] - $ca[0] + 1, $ca[3] - $ca[1] + 1);
     if ($range[0] == 0 or $range[1] == 0) {
         die("Divide by 0 imminent!");
     }
     $scaling = array($ca_range[0] / $range[0], $ca_range[1] / $range[1]);
     // Loop for each data set
     $count = 0;
     foreach ($this->data as $d) {
         unset($points);
         foreach ($d as $v) {
             $points[] = array($v[0] * $scaling[0] + ($ca[0] + 1), $ca[3] - $v[1] * $scaling[1]);
         }
         $first = 1;
         foreach ($points as $p) {
             if ($first) {
                 $lp = $p;
                 $first = 0;
             } else {
                 ImageLine($this->graph, $lp[0], $lp[1], $p[0], $p[1], $this->color['data'][$count]);
                 $lp = $p;
             }
             // Put nice circle around the point
             ImageArc($this->graph, $p[0], $p[1], 5, 5, 0, 359, $this->color['line']);
         }
         // Increment set counter
         $count++;
     }
     // Show min/max for x/y
     $fontsize = 6;
     ImageTtfText($this->graph, $fontsize, 60, $ca[0] + 4, $ca[3] + 20, $this->color['text'], $this->font, $minx);
     ImageTtfText($this->graph, $fontsize, 0, $ca[0] - 25, $ca[1] + 4, $this->color['text'], $this->font, $maxy);
     //ImageTtfText( $this->graph, $fontsize, 60, $ca[2]+4, $ca[3]+20, $this->color['text'], $this->font, $maxx );
     ImageTtfText($this->graph, $fontsize, 0, $ca[0] - 25, $ca[3] + 4, $this->color['text'], $this->font, $miny);
     // Show "steps" (5 of 'em)
     $interval = $this->interval;
     $step = array(($ca[2] - $ca[0]) / $interval, ($ca[3] - $ca[1]) / $interval);
     $count = 0;
     for ($i = $ca[0] + $step[0]; $i < $ca[2]; $i += $step[0]) {
         $count++;
         $show = $minx + $range[0] / $interval * $count;
         ImageTtfText($this->graph, $fontsize, 60, $i + 4, $ca[3] + 20, $this->color['text'], $this->font, ceil($show));
     }
     $count = 0;
     for ($i = $ca[1] + $step[1]; $i < $ca[3]; $i += $step[1]) {
         $count++;
         $show = $maxy - $range[1] / $interval * $count;
         ImageTtfText($this->graph, $fontsize, 0, $ca[0] - 25, $i + 4, $this->color['text'], $this->font, ceil($show));
     }
 }
Beispiel #20
0
function draw_spot($im, $results, $flg, $sx, $sy, $xc, $yc, $xi, $yi)
{
    $lon = $results['LON_C'];
    $lat = $results['LAT_C'];
    $diam = $results['DIAM'];
    $nb = count($lon);
    if ($flg == 0) {
        $col = ImageColorAllocate($im, 0, 0, 255 - 5 * $nb);
    } else {
        $col = ImageColorAllocate($im, 0, 255 - 5 * $nb, 255 - 5 * $nb);
    }
    for ($i = 0; $i < $nb; $i++) {
        $centX = xtrans($lon[$i] + 360 * $flg, $xc, $xi, $sx);
        $centY = ytrans($lat[$i], $yc, $yi, $sy);
        $d = xtrans($lon[$i] + $diam[$i] + 360 * $flg, $xc, $xi, $sx) - $centX;
        ImageArc($im, $centX, $centY, $d, $d, 0, 360, $col);
        //ImageFilledRectangle($im, $centX-$d, $centY-$d, $centX+$d, $centY+$d, $col);
        // remplissage
        $diameter = $d;
        while ($diameter > 0) {
            imagearc($im, $centX, $centY, $diameter, $diameter, 0, 361, $col);
            $diameter--;
        }
    }
    return $im;
}
Beispiel #21
0
 protected function DrawShape($x, $y, $record, $color, $allow_none = TRUE)
 {
     $index = $record % $this->point_counts;
     $point_size = $this->point_sizes[$index];
     $half_point = (int) ($point_size / 2);
     $x1 = $x - $half_point;
     $x2 = $x + $half_point;
     $y1 = $y - $half_point;
     $y2 = $y + $half_point;
     switch ($this->point_shapes[$index]) {
         case 'halfline':
             ImageLine($this->img, $x1, $y, $x, $y, $color);
             break;
         case 'none':
             /* Special case, no point shape here */
             if ($allow_none) {
                 break;
             }
             // But fall throught to line if a shape is required
         // But fall throught to line if a shape is required
         case 'line':
             ImageLine($this->img, $x1, $y, $x2, $y, $color);
             break;
         case 'plus':
             ImageLine($this->img, $x1, $y, $x2, $y, $color);
             ImageLine($this->img, $x, $y1, $x, $y2, $color);
             break;
         case 'cross':
             ImageLine($this->img, $x1, $y1, $x2, $y2, $color);
             ImageLine($this->img, $x1, $y2, $x2, $y1, $color);
             break;
         case 'circle':
             ImageArc($this->img, $x, $y, $point_size, $point_size, 0, 360, $color);
             break;
         case 'dot':
             ImageFilledEllipse($this->img, $x, $y, $point_size, $point_size, $color);
             break;
         case 'diamond':
             $arrpoints = array($x1, $y, $x, $y1, $x2, $y, $x, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 4, $color);
             break;
         case 'triangle':
             $arrpoints = array($x1, $y, $x2, $y, $x, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 3, $color);
             break;
         case 'trianglemid':
             $arrpoints = array($x1, $y1, $x2, $y1, $x, $y);
             ImageFilledPolygon($this->img, $arrpoints, 3, $color);
             break;
         case 'yield':
             $arrpoints = array($x1, $y1, $x2, $y1, $x, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 3, $color);
             break;
         case 'delta':
             $arrpoints = array($x1, $y2, $x2, $y2, $x, $y1);
             ImageFilledPolygon($this->img, $arrpoints, 3, $color);
             break;
         case 'star':
             ImageLine($this->img, $x1, $y, $x2, $y, $color);
             ImageLine($this->img, $x, $y1, $x, $y2, $color);
             ImageLine($this->img, $x1, $y1, $x2, $y2, $color);
             ImageLine($this->img, $x1, $y2, $x2, $y1, $color);
             break;
         case 'hourglass':
             $arrpoints = array($x1, $y1, $x2, $y1, $x1, $y2, $x2, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 4, $color);
             break;
         case 'bowtie':
             $arrpoints = array($x1, $y1, $x1, $y2, $x2, $y1, $x2, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 4, $color);
             break;
         case 'target':
             ImageFilledRectangle($this->img, $x1, $y1, $x, $y, $color);
             ImageFilledRectangle($this->img, $x, $y, $x2, $y2, $color);
             ImageRectangle($this->img, $x1, $y1, $x2, $y2, $color);
             break;
         case 'box':
             ImageRectangle($this->img, $x1, $y1, $x2, $y2, $color);
             break;
         case 'home':
             /* As in: "home plate" (baseball), also looks sort of like a house. */
             $arrpoints = array($x1, $y2, $x2, $y2, $x2, $y, $x, $y1, $x1, $y);
             ImageFilledPolygon($this->img, $arrpoints, 5, $color);
             break;
         case 'up':
             ImagePolygon($this->img, array($x, $y1, $x2, $y2, $x1, $y2), 3, $color);
             break;
         case 'down':
             ImagePolygon($this->img, array($x, $y2, $x1, $y1, $x2, $y1), 3, $color);
             break;
         default:
             /* Also 'rect' */
             ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
             break;
     }
     return TRUE;
 }
$maxlines = floor($textareay / $fontheight);
// calculate if the text fits into the space available
log2file('[drawTrm] text: ' . $text);
$text = wordwrap($text, $maxcharsperline, "\n", 1);
$lines = explode("\n", $text);
if (count($lines) > $maxlines) {
    $lines = explode("\n", "TEXT TOO LONG");
}
// centralize the text vertically
$offsety = floor(floor($textareay / 2 - ceil(count($lines) / 2 * $fontheight)) * 0.98);
// offsets to mark the textarea
$x = round(($width - $textareax) / 2);
$y = round(($height - $textareay) / 2);
// end preparations
header("Content-type: image/png");
$terminator = ImageCreate($width + 1, $height + 1);
$white = ImageColorAllocate($terminator, 255, 255, 255);
$black = ImageColorAllocate($terminator, 0, 0, 0);
$mid = round($height / 2);
ImageArc($terminator, $mid, $mid, $height, $height, 90, 270, $black);
ImageLine($terminator, $mid, 0, $width - $mid, 0, $black);
ImageArc($terminator, $width - $mid, $mid, $height, $height, 270, 90, $black);
ImageLine($terminator, $width - $mid, $height, $mid, $height, $black);
while (list($numl, $line) = each($lines)) {
    // centralize the text horizontally
    $offsetx = round(($textareax - strlen($line) * $fontwidth) / 2);
    ImageString($terminator, $font, $x + $offsetx, $y + $offsety, $line, $black);
    $offsety += $fontheight;
}
ImagePNG($terminator);
ImageDestroy($terminator);
 protected function DrawDot($x_world, $y_world, $record, $color)
 {
     $index = $record % $this->point_counts;
     $point_size = $this->point_sizes[$index];
     $half_point = (int) ($point_size / 2);
     $x_mid = $this->xtr($x_world);
     $y_mid = $this->ytr($y_world);
     $x1 = $x_mid - $half_point;
     $x2 = $x_mid + $half_point;
     $y1 = $y_mid - $half_point;
     $y2 = $y_mid + $half_point;
     switch ($this->point_shapes[$index]) {
         case 'halfline':
             ImageLine($this->img, $x1, $y_mid, $x_mid, $y_mid, $color);
             break;
         case 'line':
             ImageLine($this->img, $x1, $y_mid, $x2, $y_mid, $color);
             break;
         case 'plus':
             ImageLine($this->img, $x1, $y_mid, $x2, $y_mid, $color);
             ImageLine($this->img, $x_mid, $y1, $x_mid, $y2, $color);
             break;
         case 'cross':
             ImageLine($this->img, $x1, $y1, $x2, $y2, $color);
             ImageLine($this->img, $x1, $y2, $x2, $y1, $color);
             break;
         case 'circle':
             ImageArc($this->img, $x_mid, $y_mid, $point_size, $point_size, 0, 360, $color);
             break;
         case 'dot':
             ImageFilledEllipse($this->img, $x_mid, $y_mid, $point_size, $point_size, $color);
             break;
         case 'diamond':
             $arrpoints = array($x1, $y_mid, $x_mid, $y1, $x2, $y_mid, $x_mid, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 4, $color);
             break;
         case 'triangle':
             $arrpoints = array($x1, $y_mid, $x2, $y_mid, $x_mid, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 3, $color);
             break;
         case 'trianglemid':
             $arrpoints = array($x1, $y1, $x2, $y1, $x_mid, $y_mid);
             ImageFilledPolygon($this->img, $arrpoints, 3, $color);
             break;
         case 'yield':
             $arrpoints = array($x1, $y1, $x2, $y1, $x_mid, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 3, $color);
             break;
         case 'delta':
             $arrpoints = array($x1, $y2, $x2, $y2, $x_mid, $y1);
             ImageFilledPolygon($this->img, $arrpoints, 3, $color);
             break;
         case 'star':
             ImageLine($this->img, $x1, $y_mid, $x2, $y_mid, $color);
             ImageLine($this->img, $x_mid, $y1, $x_mid, $y2, $color);
             ImageLine($this->img, $x1, $y1, $x2, $y2, $color);
             ImageLine($this->img, $x1, $y2, $x2, $y1, $color);
             break;
         case 'hourglass':
             $arrpoints = array($x1, $y1, $x2, $y1, $x1, $y2, $x2, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 4, $color);
             break;
         case 'bowtie':
             $arrpoints = array($x1, $y1, $x1, $y2, $x2, $y1, $x2, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 4, $color);
             break;
         case 'target':
             ImageFilledRectangle($this->img, $x1, $y1, $x_mid, $y_mid, $color);
             ImageFilledRectangle($this->img, $x_mid, $y_mid, $x2, $y2, $color);
             ImageRectangle($this->img, $x1, $y1, $x2, $y2, $color);
             break;
         case 'box':
             ImageRectangle($this->img, $x1, $y1, $x2, $y2, $color);
             break;
         case 'home':
             /* As in: "home plate" (baseball), also looks sort of like a house. */
             $arrpoints = array($x1, $y2, $x2, $y2, $x2, $y_mid, $x_mid, $y1, $x1, $y_mid);
             ImageFilledPolygon($this->img, $arrpoints, 5, $color);
             break;
         case 'up':
             ImagePolygon($this->img, array($x_mid, $y1, $x2, $y2, $x1, $y2), 3, $color);
             break;
         case 'down':
             ImagePolygon($this->img, array($x_mid, $y2, $x1, $y1, $x2, $y1), 3, $color);
             break;
         case 'none':
             /* Special case, no point shape here */
             break;
         default:
             /* Also 'rect' */
             ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
             break;
     }
     return TRUE;
 }
 function RoundedImageCorners()
 {
     if (phpthumb_functions::gd_version() < 2) {
         return false;
     }
     if (!empty($this->brx) && !empty($this->bry) && $this->bw == 0) {
         $gdimg_cornermask = $this->ImageCreateFunction($this->thumbnail_width, $this->thumbnail_height);
         $background_color_cornermask = phpthumb_functions::ImageHexColorAllocate($gdimg_cornermask, $this->config_background_hexcolor);
         $border_color_cornermask = phpthumb_functions::ImageHexColorAllocate($gdimg_cornermask, $this->config_border_hexcolor);
         // Top Left
         ImageArc($gdimg_cornermask, $this->brx - 1, $this->bry - 1, $this->brx * 2, $this->bry * 2, 180, 270, $background_color_cornermask);
         ImageFillToBorder($gdimg_cornermask, 0, 0, $background_color_cornermask, $background_color_cornermask);
         // Top Right
         ImageArc($gdimg_cornermask, $this->thumbnail_width - $this->brx, $this->bry - 1, $this->brx * 2, $this->bry * 2, 270, 360, $background_color_cornermask);
         ImageFillToBorder($gdimg_cornermask, $this->thumbnail_width, 0, $background_color_cornermask, $background_color_cornermask);
         // Bottom Right
         ImageArc($gdimg_cornermask, $this->thumbnail_width - $this->brx, $this->thumbnail_height - $this->bry, $this->brx * 2, $this->bry * 2, 0, 90, $background_color_cornermask);
         ImageFillToBorder($gdimg_cornermask, $this->thumbnail_width, $this->thumbnail_height, $background_color_cornermask, $background_color_cornermask);
         // Bottom Left
         ImageArc($gdimg_cornermask, $this->brx - 1, $this->thumbnail_height - $this->bry, $this->brx * 2, $this->bry * 2, 90, 180, $background_color_cornermask);
         ImageFillToBorder($gdimg_cornermask, 0, $this->thumbnail_height, $background_color_cornermask, $background_color_cornermask);
         $transparent_color_cornermask = ImageColorTransparent($gdimg_cornermask, ImageColorAt($gdimg_cornermask, round($this->thumbnail_width / 2), round($this->thumbnail_height / 2)));
         ImageArc($gdimg_cornermask, $this->brx, $this->bry, $this->brx * 2, $this->bry * 2, 180, 270, $transparent_color_cornermask);
         ImageArc($gdimg_cornermask, $this->thumbnail_width - $this->brx, $this->bry, $this->brx * 2, $this->bry * 2, 270, 360, $transparent_color_cornermask);
         ImageArc($gdimg_cornermask, $this->thumbnail_width - $this->brx, $this->thumbnail_height - $this->bry, $this->brx * 2, $this->bry * 2, 0, 90, $transparent_color_cornermask);
         ImageArc($gdimg_cornermask, $this->brx, $this->thumbnail_height - $this->bry, $this->brx * 2, $this->bry * 2, 90, 180, $transparent_color_cornermask);
         ImageCopyMerge($this->gdimg_output, $gdimg_cornermask, 0, 0, 0, 0, $this->thumbnail_width, $this->thumbnail_height, 100);
         // Make rounded corners transparent (optional)
         if (!empty($this->bct)) {
             if ($this->bct == 256) {
                 ImageTrueColorToPalette($this->gdimg_output, true, 256);
             }
             ImageColorTransparent($this->gdimg_output, ImageColorAt($this->gdimg_output, 0, 0));
         }
     }
     return true;
 }
 function DrawDot($x_world, $y_world, $dot_type, $color)
 {
     $half_point = $this->point_size / 2;
     $x1 = $this->xtr($x_world) - $half_point;
     $x2 = $this->xtr($x_world) + $half_point;
     $y1 = $this->ytr($y_world) - $half_point;
     $y2 = $this->ytr($y_world) + $half_point;
     switch ($dot_type) {
         case "halfline":
             ImageFilledRectangle($this->img, $x1, $this->ytr($y_world), $this->xtr($x_world), $this->ytr($y_world), $color);
             break;
         case "line":
             ImageFilledRectangle($this->img, $x1, $this->ytr($y_world), $x2, $this->ytr($y_world), $color);
             break;
         case "rect":
             ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
             break;
         case "circle":
             ImageArc($this->img, $x1 + $half_point, $y1 + $half_point, $this->point_size, $this->point_size, 0, 360, $color);
             break;
         case "dot":
             ImageArc($this->img, $x1 + $half_point, $y1 + $half_point, $this->point_size, $this->point_size, 0, 360, $color);
             ImageFillToBorder($this->img, $x1 + $half_point, $y1 + $half_point, $color, $color);
             break;
         case "diamond":
             $arrpoints = array($x1, $y1 + $half_point, $x1 + $half_point, $y1, $x2, $y1 + $half_point, $x1 + $half_point, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 4, $color);
             break;
         case "triangle":
             $arrpoints = array($x1, $y1 + $half_point, $x2, $y1 + $half_point, $x1 + $half_point, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 3, $color);
             break;
         default:
             ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
             break;
     }
     return true;
 }
Beispiel #26
0
srand((double) microtime() * 1000000);
$im = ImageCreate($w, $h);
$bgcolor = ImageColorAllocate($im, 255, 255, 255);
ImageFill($im, 0, 0, $bgcolor);
if ($border) {
    $black = ImageColorAllocate($im, 0, 0, 0);
    ImageRectangle($im, 0, 0, $w - 1, $h - 1, $black);
}
for ($i = 0; $i < $how; $i++) {
    $alpha_or_number = mt_rand(0, 1);
    $str = $alpha_or_number ? $alpha : $number;
    $which = mt_rand(0, strlen($str) - 1);
    $code = substr($str, $which, 1);
    $j = !$i ? 4 : $j + 15;
    $color3 = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
    ImageChar($im, $fontsize, $j, 3, $code, $color3);
    $randcode .= $code;
}
for ($i = 0; $i < 5; $i++) {
    $color1 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
    ImageArc($im, mt_rand(-5, $w), mt_rand(-5, $h), mt_rand(20, 300), mt_rand(20, 200), 55, 44, $color1);
}
for ($i = 0; $i < $how * 40; $i++) {
    $color2 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
    ImageSetPixel($im, mt_rand(0, $w), mt_rand(0, $h), $color2);
}
$_SESSION['randcode'] = $randcode;
Imagegif($im);
ImageDestroy($im);
?>
 
Beispiel #27
0
 public function ImageBorder(&$gdimg, $border_width, $radius_x, $radius_y, $hexcolor_border)
 {
     $border_width = $border_width ? $border_width : 1;
     $radius_x = $radius_x ? $radius_x : 0;
     $radius_y = $radius_y ? $radius_y : 0;
     $output_width = ImageSX($gdimg);
     $output_height = ImageSY($gdimg);
     list($new_width, $new_height) = phpthumb_functions::ProportionalResize($output_width, $output_height, $output_width - max($border_width * 2, $radius_x), $output_height - max($border_width * 2, $radius_y));
     $offset_x = $radius_x ? $output_width - $new_width - $radius_x : 0;
     $offset_y = $radius_y ? $output_height - $new_height - $radius_y : 0;
     //header('Content-Type: image/png');
     //ImagePNG($gdimg);
     //exit;
     if ($gd_border_canvas = phpthumb_functions::ImageCreateFunction($output_width, $output_height)) {
         ImageSaveAlpha($gd_border_canvas, true);
         ImageAlphaBlending($gd_border_canvas, false);
         $color_background = phpthumb_functions::ImageColorAllocateAlphaSafe($gd_border_canvas, 255, 255, 255, 127);
         ImageFilledRectangle($gd_border_canvas, 0, 0, $output_width, $output_height, $color_background);
         $color_border = phpthumb_functions::ImageHexColorAllocate($gd_border_canvas, phpthumb_functions::IsHexColor($hexcolor_border) ? $hexcolor_border : '000000');
         for ($i = 0; $i < $border_width; $i++) {
             ImageLine($gd_border_canvas, floor($offset_x / 2) + $radius_x, $i, $output_width - $radius_x - ceil($offset_x / 2), $i, $color_border);
             // top
             ImageLine($gd_border_canvas, floor($offset_x / 2) + $radius_x, $output_height - 1 - $i, $output_width - $radius_x - ceil($offset_x / 2), $output_height - 1 - $i, $color_border);
             // bottom
             ImageLine($gd_border_canvas, floor($offset_x / 2) + $i, $radius_y, floor($offset_x / 2) + $i, $output_height - $radius_y, $color_border);
             // left
             ImageLine($gd_border_canvas, $output_width - 1 - $i - ceil($offset_x / 2), $radius_y, $output_width - 1 - $i - ceil($offset_x / 2), $output_height - $radius_y, $color_border);
             // right
         }
         if ($radius_x && $radius_y) {
             // PHP bug: ImageArc() with thicknesses > 1 give bad/undesirable/unpredicatable results
             // Solution: Draw multiple 1px arcs side-by-side.
             // Problem: parallel arcs give strange/ugly antialiasing problems
             // Solution: draw non-parallel arcs, from one side of the line thickness at the start angle
             //   to the opposite edge of the line thickness at the terminating angle
             for ($thickness_offset = 0; $thickness_offset < $border_width; $thickness_offset++) {
                 ImageArc($gd_border_canvas, floor($offset_x / 2) + 1 + $radius_x, $thickness_offset - 1 + $radius_y, $radius_x * 2, $radius_y * 2, 180, 270, $color_border);
                 // top-left
                 ImageArc($gd_border_canvas, $output_width - $radius_x - 1 - ceil($offset_x / 2), $thickness_offset - 1 + $radius_y, $radius_x * 2, $radius_y * 2, 270, 360, $color_border);
                 // top-right
                 ImageArc($gd_border_canvas, $output_width - $radius_x - 1 - ceil($offset_x / 2), $output_height - $thickness_offset - $radius_y, $radius_x * 2, $radius_y * 2, 0, 90, $color_border);
                 // bottom-right
                 ImageArc($gd_border_canvas, floor($offset_x / 2) + 1 + $radius_x, $output_height - $thickness_offset - $radius_y, $radius_x * 2, $radius_y * 2, 90, 180, $color_border);
                 // bottom-left
             }
             if ($border_width > 1) {
                 for ($thickness_offset = 0; $thickness_offset < $border_width; $thickness_offset++) {
                     ImageArc($gd_border_canvas, floor($offset_x / 2) + $thickness_offset + $radius_x, $radius_y, $radius_x * 2, $radius_y * 2, 180, 270, $color_border);
                     // top-left
                     ImageArc($gd_border_canvas, $output_width - $thickness_offset - $radius_x - 1 - ceil($offset_x / 2), $radius_y, $radius_x * 2, $radius_y * 2, 270, 360, $color_border);
                     // top-right
                     ImageArc($gd_border_canvas, $output_width - $thickness_offset - $radius_x - 1 - ceil($offset_x / 2), $output_height - $radius_y, $radius_x * 2, $radius_y * 2, 0, 90, $color_border);
                     // bottom-right
                     ImageArc($gd_border_canvas, floor($offset_x / 2) + $thickness_offset + $radius_x, $output_height - $radius_y, $radius_x * 2, $radius_y * 2, 90, 180, $color_border);
                     // bottom-left
                 }
             }
         }
         $this->phpThumbObject->ImageResizeFunction($gd_border_canvas, $gdimg, floor(($output_width - $new_width) / 2), round(($output_height - $new_height) / 2), 0, 0, $new_width, $new_height, $output_width, $output_height);
         ImageDestroy($gdimg);
         $gdimg = phpthumb_functions::ImageCreateFunction($output_width, $output_height);
         ImageSaveAlpha($gdimg, true);
         ImageAlphaBlending($gdimg, false);
         $gdimg_color_background = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg, 255, 255, 255, 127);
         ImageFilledRectangle($gdimg, 0, 0, $output_width, $output_height, $gdimg_color_background);
         ImageCopy($gdimg, $gd_border_canvas, 0, 0, 0, 0, $output_width, $output_height);
         //$gdimg = $gd_border_canvas;
         ImageDestroy($gd_border_canvas);
         return true;
     } else {
         $this->DebugMessage('FAILED: $gd_border_canvas = phpthumb_functions::ImageCreateFunction(' . $output_width . ', ' . $output_height . ')', __FILE__, __LINE__);
     }
     return false;
 }
Beispiel #28
0
<?php

ImageArc($image, $x, $y, $width, $height, $start, $end, $color);
Beispiel #29
0
 function DrawDot($x_world, $y_world, $record, $color)
 {
     // TODO: optimize, avoid counting every time we are called.
     $record = $record % count($this->point_shapes);
     $half_point = $this->point_sizes[$record] / 2;
     $x_mid = $this->xtr($x_world);
     $y_mid = $this->ytr($y_world);
     $x1 = $x_mid - $half_point;
     $x2 = $x_mid + $half_point;
     $y1 = $y_mid - $half_point;
     $y2 = $y_mid + $half_point;
     switch ($this->point_shapes[$record]) {
         case 'halfline':
             ImageLine($this->img, $x1, $y_mid, $x_mid, $y_mid, $color);
             break;
         case 'line':
             ImageLine($this->img, $x1, $y_mid, $x2, $y_mid, $color);
             break;
         case 'plus':
             ImageLine($this->img, $x1, $y_mid, $x2, $y_mid, $color);
             ImageLine($this->img, $x_mid, $y1, $x_mid, $y2, $color);
             break;
         case 'cross':
             ImageLine($this->img, $x1, $y1, $x2, $y2, $color);
             ImageLine($this->img, $x1, $y2, $x2, $y1, $color);
             break;
         case 'rect':
             ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
             break;
         case 'circle':
             ImageArc($this->img, $x_mid, $y_mid, $this->point_sizes[$record], $this->point_sizes[$record], 0, 360, $color);
             break;
         case 'dot':
             ImageFilledArc($this->img, $x_mid, $y_mid, $this->point_sizes[$record], $this->point_sizes[$record], 0, 360, $color, IMG_ARC_PIE);
             break;
         case 'diamond':
             $arrpoints = array($x1, $y_mid, $x_mid, $y1, $x2, $y_mid, $x_mid, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 4, $color);
             break;
         case 'triangle':
             $arrpoints = array($x1, $y_mid, $x2, $y_mid, $x_mid, $y2);
             ImageFilledPolygon($this->img, $arrpoints, 3, $color);
             break;
         case 'trianglemid':
             $arrpoints = array($x1, $y1, $x2, $y1, $x_mid, $y_mid);
             ImageFilledPolygon($this->img, $arrpoints, 3, $color);
             break;
         case 'none':
             break;
         default:
             ImageFilledRectangle($this->img, $x1, $y1, $x2, $y2, $color);
             break;
     }
     return TRUE;
 }
 public function get_image($session_key = 'captcha')
 {
     header("Content-type:image/png");
     if (!isset($_SESSION)) {
         session_start();
     }
     /*
      * 初始化
      */
     $border = 0;
     //是否要边框 1要:0不要
     $how = $this->code_num;
     //验证码位数
     $w = $this->width;
     //图片宽度
     $h = $this->height;
     //图片高度
     $fontsize = 20;
     //字体大小
     $alpha = "ABCDEFGHJKLMNPQRSTUVWXYZ";
     //验证码内容1:字母
     $number = "23456789";
     //验证码内容2:数字
     $randcode = "";
     //验证码字符串初始化
     $font_url = 'fonts/simhei.ttf';
     srand((double) microtime() * 1000000);
     //初始化随机数种子
     $im = ImageCreate($w, $h);
     //创建验证图片
     /*
      * 绘制基本框架
      */
     $bgcolor = ImageColorAllocate($im, 255, 255, 255);
     //设置背景颜色
     ImageFill($im, 0, 0, $bgcolor);
     //填充背景色
     if ($border) {
         $black = ImageColorAllocate($im, 0, 0, 0);
         //设置边框颜色
         ImageRectangle($im, 0, 0, $w - 1, $h - 1, $black);
         //绘制边框
     }
     /*
      * 逐位产生随机字符
      */
     for ($i = 0; $i < $how; $i++) {
         $alpha_or_number = mt_rand(0, 1);
         //字母还是数字
         $str = $alpha_or_number ? $alpha : $number;
         $which = mt_rand(0, strlen($str) - 1);
         //取哪个字符
         $code = substr($str, $which, 1);
         //取字符
         $j = !$i ? 15 : $j + 12;
         //绘字符位置
         $color3 = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
         //字符随即颜色
         #ImageChar($im, $fontsize, $j, 6, $code, $color3); //绘字符
         //旋转角度随机数
         $angel_rand_1 = mt_rand(-15, -10);
         $angel_rand_2 = mt_rand(10, 15);
         $angel_rand_change = mt_rand(0, 1);
         $angel_rand = $angel_rand_change == 1 ? $angel_rand_1 : $angel_rand_2;
         ImageTTFText($im, $fontsize, $angel_rand, $j, 25, $color3, $font_url, $code);
         $randcode .= $code;
         //逐位加入验证码字符串
     }
     /*
      * 添加干扰
      */
     for ($i = 0; $i < 5; $i++) {
         $color1 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         //干扰线颜色
         ImageArc($im, mt_rand(-5, $w), mt_rand(-5, $h), mt_rand(20, 300), mt_rand(20, 200), 55, 44, $color1);
         //干扰线
     }
     for ($i = 0; $i < $how * 40; $i++) {
         $color2 = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         //干扰点颜色
         ImageSetPixel($im, mt_rand(0, $w), mt_rand(0, $h), $color2);
         //干扰点
     }
     //把验证码字符串写入session
     $_SESSION[$session_key] = $randcode;
     /*绘图结束*/
     Imagegif($im);
     ImageDestroy($im);
     /*绘图结束*/
 }