$char, 'size' => $size, 'angle' => $angle, 'height' => $char_height, 'width' => $char_width, ); } /* calculate the final image size, adding some padding */ $x_padding = 12; if ( $CSize == 1 ) { $image_width += ($x_padding * 2); $image_height = ($image_height * 1.5) + 2; } else { $image_width = $CSizeWidth; $image_height = $CSizeHeight; } /* build the image, and allocte the colors */ $im = ImageCreate($image_width, $image_height); $cs = mt_rand(1,3); if ($CBackgroundType == 2) { $r = hexdec(substr($CBackgroundColor,1,2)); $g = hexdec(substr($CBackgroundColor,3,2)); $b = hexdec(substr($CBackgroundColor,5,2)); } else { $d1 = $d2 = $d3 = 0; while ( ($d1<50) AND ($d2<50) AND (d3<50) ) { $r = mt_rand(200,255); $g = mt_rand(200,255); $b = mt_rand(200,255); $d1 = abs($r-$g); $d2 = abs($r-$b); $d3 = abs($g-$b); } } $color_bg = ImageColorAllocate($im, $r, $g, $b ); $color_border = ImageColorAllocate($im, round($r/2), round($g/2), round($b/2)); $color_line0 = ImageColorAllocate($im, round($r*0.85), round($g*0.85), round($b*0.85) ); $color_elipse0 = ImageColorAllocate($im, round($r*0.95), round($g*0.95), round($b*0.95) ); $color_elipse1 = ImageColorAllocate($im, round($r*0.90), round($g*0.90), round($b*0.90) ); $d1 = mt_rand(0,50); $d2 = mt_rand(0,50); $d3 = mt_rand(0,50); $color_line1 = ImageColorAllocate($im, $r-$d1, $g-$d2, $b-$d3 ); $d1 = $d2 = $d3 = 0; while ( ($d1<100) AND ($d2<100) AND (d3<100) ) { $r = mt_rand(0,150); $g = mt_rand(0,150); $b = mt_rand(0,150); $d1 = abs($r-$g); $d2 = abs($r-$b); $d3 = abs($g-$b); } switch ( $CFontColorType ) { case 1 : $color_text = ImageColorAllocate($im, $r, $g, $b ); break; case 2 : $color_text = ImageColorAllocate($im, 0, 0, 0 ); break; case 3 : $color_text = ImageColorAllocate($im, 255, 255, 255 ); break; case 4 : $color_text_r = hexdec(substr($CFontColor,1,2)); $color_text_g = hexdec(substr($CFontColor,3,2)); $color_text_b = hexdec(substr($CFontColor,5,2)); $color_text = ImageColorAllocate($im, $color_text_r, $color_text_g, $color_text_b ); break; } $noiset = mt_rand(1,2); if ( $CBackgroundType == 1 ) { switch ($noiset) { case '1' : /* make the random background elipses */ for($l=0; $l<10; $l++) { $c = 'color_elipse' . ($l%2); $cx = mt_rand(0, $image_width); $cy = mt_rand(0, $image_width); $rx = mt_rand(10, $image_width); $ry = mt_rand(10, $image_width); ImageFilledEllipse($im, $cx, $cy, $rx, $ry, $$c ); }; break; case '2' : /* make the random background lines */ for($l=0; $l<10; $l++) { $c = 'color_line' . ($l%2); $lx = mt_rand(0, $image_width+$image_height); $lw = mt_rand(0,3); if ($lx > $image_width) { $lx -= $image_width; ImageFilledRectangle($im, 0, $lx, $image_width-1, $lx+$lw, $c ); } else ImageFilledRectangle($im, $lx, 0, $lx+$lw, $image_height-1, $c ); }; break; } // end switch } if ( $CBackgroundType == 0 ) { $image_data=getimagesize($CBackgroundFile); $image_type=$image_data[2]; if($image_type==1) $img_src=imagecreatefromgif($CBackgroundFile); elseif($image_type==2) $img_src=imagecreatefromjpeg($CBackgroundFile); elseif($image_type==3) $img_src=imagecreatefrompng($CBackgroundFile); if ( $CBackgroundFillType == 1 ) { imagesettile($im,$img_src); imagefill($im,0,0,IMG_COLOR_TILED); } else imagecopyresampled($im,$img_src,0,0,0,0,$image_width,$image_height,$image_data[0],$image_data[1]); } /* output each character */ $pos_x = $x_padding + ($CFontPadding / 2); foreach($data as $d) { $pos_y = ( ( $image_height + $d['height'] ) / 2 ); ImageTTFText($im, $d['size'], $d['angle'], $pos_x, $pos_y, $color_text, $font, $d['char'] ); $pos_x += $d['width'] + $CFontPadding; } if ($CNoise == 1) { $color_noise_r = hexdec(substr($CNoiseColor,1,2)); $color_noise_g = hexdec(substr($CNoiseColor,3,2)); $color_noise_b = hexdec(substr($CNoiseColor,5,2)); $color_noise = ImageColorAllocate($im, $color_noise_r, $color_noise_g, $color_noise_b); if ($CNoiseType == 0) $CNoiseType = mt_rand(1,4); for ($i=1;$i<10;$i++) switch ($CNoiseType) { case 1 : // draw lines $direction = mt_rand(0,1); if ($direction == 0 ) { // horizontal line $x1 = 0; $x2 = $image_width; $y1 = $y2 = mt_rand(0, $image_height); } if ($direction == 1 ) { // vertical line $y1 = 0; $y2 = $image_height; $x1 = $x2 = mt_rand(0, $image_width); } imageline ($im, $x1, $y1, $x2, $y2, $color_noise ); break; case 2 : // draw circles $cx = mt_rand(0, $image_width); $cy = mt_rand(0, $image_height); $width = mt_rand(0, $image_width * 2); $height = mt_rand(0, $image_height * 2); imageellipse($im, $cx, $cy, $width, $height, $color_noise ); break; case 3 : // draw triangles $x1 = mt_rand(0, $image_width); $y1 = mt_rand(0, $image_height); $x2 = mt_rand(0, $image_width); $y2 = mt_rand(0, $image_height); $x3 = mt_rand(0, $image_width); $y4 = mt_rand(0, $image_height); imageline ($im, $x1, $y1, $x2, $y2, $color_noise ); imageline ($im, $x2, $y2, $x3, $y3, $color_noise ); imageline ($im, $x3, $y3, $x1, $y1, $color_noise ); break; case 4 : // draw lines $x1 = mt_rand(0, $image_width); $y1 = mt_rand(0, $image_height); $x2 = mt_rand(0, $image_width); $y2 = mt_rand(0, $image_height); imageline ($im, $x1, $y1, $x2, $y2, $color_noise ); break; } } /* a nice border */ ImageRectangle($im, 0, 0, $image_width-1, $image_height-1, $color_border); /* display it */ switch ($output_type) { case 'jpeg': Header('Content-type: image/jpeg'); ImageJPEG($im,NULL,100); break; case 'png': default: Header('Content-type: image/png'); ImagePNG($im); break; } ImageDestroy($im); break; case 2: break; } session_write_close(); ?>