Example #1
0
function draw_captcha($security_code)
{
    //Set the image width and height
    $width = 100;
    $height = 25;
    //Create the image resource
    $image = ImageCreate($width, $height);
    if (function_exists('imageantialias')) {
        imageantialias($image, true);
    }
    //We are making three colors, white, black and gray
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 15, 50, 15);
    $grey = ImageColorAllocate($image, 204, 204, 204);
    $ellipsec = ImageColorAllocate($image, 0, 100, 60);
    //Make the background black
    ImageFill($image, 0, 0, $black);
    imagefilledellipse($image, 56, 15, 30, 17, $ellipsec);
    //Add randomly generated string in white to the image
    ImageString($image, 5, 30, 4, $security_code, $white);
    //Throw in some lines to make it a little bit harder for any bots to break
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
    imageline($image, 0, $height / 2 + 3, $width, $height / 2 + 5, $grey);
    imageline($image, $width / 2 - 14, 0, $width / 2 + 7, $height, $grey);
    //Tell the browser what kind of file is come in
    header("Content-Type: image/jpeg");
    //Output the newly created image in jpeg format
    ImageJpeg($image);
    //Free up resources
    ImageDestroy($image);
}
Example #2
0
function drawRating()
{
    $width = $_GET['width'];
    $height = $_GET['height'];
    if ($width == 0) {
        $width = 200;
    }
    if ($height == 0) {
        $height = 7;
    }
    $rating = $_GET['rating'];
    $ratingbar = $rating / 100 * $width - 2;
    $image = imagecreate($width, $height);
    $fill = ImageColorAllocate($image, 0, 255, 0);
    if ($rating > 49) {
        $fill = ImageColorAllocate($image, 255, 255, 0);
    }
    if ($rating > 74) {
        $fill = ImageColorAllocate($image, 255, 128, 0);
    }
    if ($rating > 89) {
        $fill = ImageColorAllocate($image, 255, 0, 0);
    }
    $back = ImageColorAllocate($image, 205, 205, 205);
    $border = ImageColorAllocate($image, 0, 0, 0);
    ImageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $back);
    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $fill);
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border);
    imagePNG($image);
    imagedestroy($image);
}
Example #3
0
function create_image()
{
    //Let's generate a totally random string using md5
    $md5_hash = md5(rand(0, 999));
    //We don't need a 32 character long string so we trim it down to 5
    $security_code = substr($md5_hash, 15, 5);
    //Set the session to store the security code
    $_SESSION["captchaCode"] = $security_code;
    //Set the image width and height
    $width = 100;
    $height = 20;
    //Create the image resource
    $image = ImageCreate($width, $height);
    //We are making three colors, white, black and gray
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 0, 0, 0);
    $grey = ImageColorAllocate($image, 204, 204, 204);
    //Make the background black
    ImageFill($image, 0, 0, $black);
    //Add randomly generated string in white to the image
    ImageString($image, 3, 30, 3, $security_code, $white);
    //Throw in some lines to make it a little bit harder for any bots to break
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
    imageline($image, 0, $height / 2, $width, $height / 2, $grey);
    imageline($image, $width / 2, 0, $width / 2, $height, $grey);
    //Tell the browser what kind of file is come in
    header("Content-Type: image/jpeg");
    //Output the newly created image in jpeg format
    ImageJpeg($image);
    //Free up resources
    ImageDestroy($image);
}
Example #4
0
function drawRating($rating) {
   $width = $_GET['width'];
   $height = $_GET['height'];
   if ($width == 0) {
     $width = 102;
   }
   if ($height == 0) {
     $height = 10;
   }

   $rating = $_GET['rating'];
   $ratingbar = (($rating/100)*$width)-2;

   $image = imagecreate($width,$height);
   //colors
   $back = ImageColorAllocate($image,255,255,255);
   $border = ImageColorAllocate($image,0,0,0);
   $red = ImageColorAllocate($image,255,60,75);
   $fill = ImageColorAllocate($image,44,81,150);

   ImageFilledRectangle($image,0,0,$width-1,$height-1,$back);
   ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$fill);
   ImageRectangle($image,0,0,$width-1,$height-1,$border);
   imagePNG($image);
   imagedestroy($image);
}
Example #5
0
function drawRating($rating, $max, $type)
{
    if ($type == 0) {
        $image = imagecreatetruecolor(102, 15);
        $back = ImageColorAllocate($image, 250, 250, 250);
        $border = ImageColorAllocate($image, 0, 0, 0);
        $fill = ImageColorAllocate($image, 0, 235, 0);
        ImageFilledRectangle($image, 0, 0, 101, 14, $back);
        ImageFilledRectangle($image, 1, 1, $rating / $max * 100, 14, $fill);
        ImageRectangle($image, 0, 0, 101, 14, $border);
        $textcolor = imagecolorallocate($image, 0, 0, 0);
        imagestring($image, 5, 35, 0, $rating / $max * 100 . '%', $textcolor);
    } else {
        if ($rating > $max) {
            $rating = $max;
        }
        $image = imagecreatetruecolor(10 * ($rating + 2) + 2, 15);
        $back = ImageColorAllocate($image, 250, 250, 250);
        $border = ImageColorAllocate($image, 0, 0, 0);
        $fill = ImageColorAllocate($image, 235, 0, 0);
        ImageFilledRectangle($image, 0, 0, 10 * ($rating + 2) + 1, 14, $back);
        ImageFilledRectangle($image, 1, 1, 10 * $rating, 14, $fill);
        ImageRectangle($image, 0, 0, 10 * $rating + 1, 14, $border);
        $textcolor = imagecolorallocate($image, 0, 0, 0);
        imagestring($image, 5, 10 * ($rating + 1), 0, $rating, $textcolor);
    }
    imagepng($image);
    imagedestroy($image);
}
Example #6
0
function drawRating($rating)
{
    $width = 300;
    $height = 15;
    $ratingbar = $rating / 100 * $width - 2;
    $image = imagecreate($width, $height);
    $fill = ImageColorAllocate($image, 67, 219, 0);
    if ($rating > 74) {
        $fill = ImageColorAllocate($image, 233, 233, 0);
    }
    if ($rating > 89) {
        $fill = ImageColorAllocate($image, 197, 6, 6);
    }
    if ($rating > 100) {
        echo "Overload Error!";
        exit;
    }
    $back = ImageColorAllocate($image, 255, 255, 255);
    $border = ImageColorAllocate($image, 151, 151, 151);
    ImageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $back);
    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $fill);
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border);
    imagePNG($image);
    imagedestroy($image);
}
Example #7
0
 /**
  * Generates a random captcha image
  *
  **/
 function display($cachable = false, $urlparams = false)
 {
     // @TODO: Run some cleaning query here to clear the database.
     JTable::addIncludePath(DISCUSS_TABLES);
     $id = JRequest::getInt('captcha-id', '');
     $captcha = DiscussHelper::getTable('Captcha');
     // clearing the oudated keys.
     $captcha->clear();
     // load the captcha records.
     $captcha->load($id);
     if (!$captcha->id) {
         return false;
     }
     // @task: Generate a very random integer and take only 5 chars max.
     $hash = JString::substr(md5(rand(0, 9999)), 0, 5);
     $captcha->response = $hash;
     $captcha->store();
     // Captcha width and height
     $width = 100;
     $height = 20;
     $image = ImageCreate($width, $height);
     $white = ImageColorAllocate($image, 255, 255, 255);
     $black = ImageColorAllocate($image, 0, 0, 0);
     $gray = ImageColorAllocate($image, 204, 204, 204);
     ImageFill($image, 0, 0, $white);
     ImageString($image, 5, 30, 3, $hash, $black);
     ImageRectangle($image, 0, 0, $width - 1, $height - 1, $gray);
     imageline($image, 0, $height / 2, $width, $height / 2, $gray);
     imageline($image, $width / 2, 0, $width / 2, $height, $gray);
     header('Content-type: image/jpeg');
     ImageJpeg($image);
     ImageDestroy($image);
     exit;
 }
Example #8
0
 private function makeBorder()
 {
     $bgcolor = ImageColorAllocate($this->image, $this->bordercolor[0], $this->bordercolor[1], $this->bordercolor[2]);
     // 邊框顏色
     ImageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $bgcolor);
     // 製作邊框
 }
 function createImage($_text, $_fontsize = 11)
 {
     /* create filename */
     $filename = 'button_' . md5($_text) . '.png';
     $filename = strtolower($filename);
     /* see if file exists already, we cache it */
     if (file_exists(PHPGW_IMAGES_FILEDIR . '/' . $filename)) {
         return $filename;
     }
     $size = imagettfbbox($_fontsize, 0, $this->font, $_text);
     $dx = abs($size[2] - $size[0]);
     $dy = abs($size[5] - $size[3]);
     $xpad = 9;
     $ypad = 9;
     $im = imagecreate($dx + $xpad, $dy + $ypad);
     $blue = ImageColorAllocate($im, 0x2c, 0x6d, 0xaf);
     $black = ImageColorAllocate($im, 0, 0, 0);
     $white = ImageColorAllocate($im, 255, 255, 255);
     ImageRectangle($im, 0, 0, $dx + $xpad - 1, $dy + $ypad - 1, $black);
     ImageRectangle($im, 0, 0, $dx + $xpad, $dy + $ypad, $white);
     ImageTTFText($im, $_fontsize, 0, (int) ($xpad / 2) + 1, $dy + (int) ($ypad / 2), -$black, $this->font, $_text);
     ImageTTFText($im, $_fontsize, 0, (int) ($xpad / 2), $dy + (int) ($ypad / 2) - 1, -$white, $this->font, $_text);
     ImagePNG($im, PHPGW_IMAGES_FILEDIR . '/' . $filename);
     ImageDestroy($im);
     return $filename;
 }
Example #10
0
 /**
  * Generates the captcha image
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return	
  */
 public function generate()
 {
     $id = $this->input->get('id', '', 'int');
     // Load up the captcha object
     $captcha = EB::table('Captcha');
     // Clear outdated keys
     $captcha->clear();
     // load the captcha records.
     $captcha->load($id);
     if (!$captcha->id) {
         return false;
     }
     // @task: Generate a very random integer and take only 5 chars max.
     $hash = JString::substr(md5(rand(0, 9999)), 0, 5);
     $captcha->response = $hash;
     $captcha->store();
     // Captcha width and height
     $width = 100;
     $height = 20;
     $image = ImageCreate($width, $height);
     $white = ImageColorAllocate($image, 255, 255, 255);
     $black = ImageColorAllocate($image, 0, 0, 0);
     $gray = ImageColorAllocate($image, 204, 204, 204);
     ImageFill($image, 0, 0, $white);
     ImageString($image, 5, 30, 3, $hash, $black);
     ImageRectangle($image, 0, 0, $width - 1, $height - 1, $gray);
     imageline($image, 0, $height / 2, $width, $height / 2, $gray);
     imageline($image, $width / 2, 0, $width / 2, $height, $gray);
     header('Content-type: image/jpeg');
     ImageJpeg($image);
     ImageDestroy($image);
     exit;
 }
 function create_image($string_captcha, $width = 130, $height = 35)
 {
     //Let's generate a totally random string using md5
     //    $md5_hash = md5(rand(0,999));
     //We don't need a 32 character long string so we trim it down to 5
     //    $security_code = substr($md5_hash, 15, 5);
     $security_code = $string_captcha;
     /* ********************************************
        Use this part if you need to Set the session 
        to store the security code                */
     $_SESSION['security_code'] = $security_code;
     $CodeInd = 0;
     $arrSecCode = array();
     $chars = preg_split('//', $security_code);
     $security_code = implode(" ", $chars);
     //Set the image width and height
     //$width = 130;
     //$height = 35;
     //Create the image resource
     $image = ImageCreate($width, $height);
     //We are making three colors, white, black and gray
     $arrB = array(0, 255, 129, 10, 48, 200, 186);
     $arrR = array(0, 255, 129, 111, 48, 210, 126);
     $arrG = array(0, 205, 139, 110, 48, 5, 186);
     $black = ImageColorAllocate($image, $arrR[rand(0, 6)], $arrG[rand(0, 6)], $arrB[rand(0, 6)]);
     $white = ImageColorAllocate($image, 255, 255, 255);
     $grey = ImageColorAllocate($image, 175, 253, 253);
     //Make the background black
     ImageFill($image, 0, 0, $black);
     $font = 5;
     $arrSel = array(1, 2, 3, 4);
     $selectedNum = $arrSel[rand(0, 3)];
     ImageString($image, $font, 10, 10, $security_code, $white);
     //Throw in some lines to make it a little bit harder for any bots to break
     ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
     if ($selectedNum == 1) {
         imageline($image, 0, $height / 2, $width, $height / 5, $grey);
         imageline($image, $width / 2, 0, $width / 3, $height / 5, $grey);
         imageline($image, $width / 2, 0, $width / 10, $height, $grey);
         imageline($image, $width / 2, 0, $width / 10, $height / 6, $grey);
     }
     if ($selectedNum == 2) {
         imageline($image, $width / 1, 0, $width / 6, $height, $grey);
         imageline($image, 0, $height / 5, $width, $height / 8, $grey);
         imageline($image, 0, $height / 5, $width / 5, $height / 8, $grey);
         imageline($image, 0, $height / 3, $width, $height, $grey);
     }
     if ($selectedNum == 3) {
         imageline($image, 0, $height, $width, 0, $grey);
         imageline($image, 0, 0, $height, $height, $grey);
         imageline($image, $width / 5, 0, $width / 6, $height, $grey);
         imageline($image, $width / 4, 0, $width / 4, $height, $grey);
     }
     //Tell the browser what kind of file is come in
     header("Content-Type: image/jpeg");
     //Output the newly created image in jpeg format
     ImageJpeg($image);
     //Free up resources
     ImageDestroy($image);
 }
function doFilledBlock()
{
    global $sx, $sy, $im, $pink, $black, $mark_v_offset;
    $width = 10;
    $height = 5;
    $ex = $sx + $width;
    $ey = $sy + $height + $mark_v_offset;
    ImageRectangle($im, $sx, $sy + $mark_v_offset, $ex, $ey, $pink);
    ImageFilledRectangle($im, $sx + 1, $sy + $mark_v_offset + 1, $ex - 1, $ey - 1, $black);
}
Example #13
0
function drawBorder(&$img, &$color, $thickness = 1)
{
    $x1 = 0;
    $y1 = 0;
    $x2 = ImageSX($img) - 1;
    $y2 = ImageSY($img) - 1;
    for ($i = 0; $i < $thickness; $i++) {
        ImageRectangle($img, $x1++, $y1++, $x2--, $y2--, $color_black);
    }
}
 function display($db_object, $common, $user_id, $default, $error_msg, $learning, $post_var)
 {
     $width = 340;
     $height = 220;
     //	$labelfont = '2';
     $labeltitlefont = '3';
     $image = ImageCreate($width, $height);
     while (list($kk, $vv) = @each($post_var)) {
         ${$kk} = $vv;
     }
     /*
     $to_date=2004-01-02;
     $from_date=2004-01-02;
     $avg_rater=50.23;
     */
     $bgcolor = ImageColorAllocate($image, 0xffffff, 0xffffff, 0xffffff);
     $border = ImageColorAllocate($image, 0x0, 0x0, 0x0);
     $border1 = ImageColorAllocate($image, 0xcccccc, 0x0, 0x0);
     //$border2 = ImageColorAllocate($image,0x000000, 0xcccccc, 0x000000);
     ImageRectangle($image, 40, 20, 240, 160, $border);
     ImageString($image, $labelfont, 15, 20, "100%", $border);
     ImageString($image, $labelfont, 20, 55, "75%", $border);
     ImageString($image, $labelfont, 20, 90, "50%", $border);
     ImageString($image, $labelfont, 20, 125, "25%", $border);
     ImageString($image, $labelfont, 20, 155, "0%", $border);
     $fdate = $learning->changedate_display($from_date);
     $tdate = $learning->changedate_display($to_date);
     $days = $error_msg['cDays'] . " {$fdate} " . $error_msg['cTo'] . " {$tdate} ";
     $avg_rt = @explode(",", $avg_rater);
     $id = @explode(",", $ids);
     for ($i = 0; $i < count($avg_rt); $i++) {
         $p1 = rand(0, 200);
         $p2 = rand(30, 250);
         $p3 = rand(100, 250);
         $color = imagecolorallocate($image, $p1, $p2, $p3);
         $avg = $avg_rt[$i];
         $avg_comp = 160 - 140 / 100 * $avg;
         $avg = round($avg, 2);
         $rid = $id[$i];
         $rname = $common->name_display($db_object, $rid);
         ImageStringUp($image, $labeltitlefont, 5, 110, $error_msg['cResults'], $border);
         ImageString($image, $labeltitlefont, 245, 20, $error_msg['cCommitment'], $border);
         ImageString($image, $labeltitlefont, 50, 170, "{$days}", $border);
         //ImageString($image, $labeltitlefont, 50,180, "$rname", $color);
         ImageLine($image, 240, 20, 40, 160, $border1);
         //COMMITMENT LINE
         ImageLine($image, 240, $avg_comp, 40, 160, $color);
         //AVERAGE COMPLETION
         header("Content-type: image/png");
         // or "Content-type: image/png"
         Imagepng($image);
         // or imagepng($image)
     }
     ImageDestroy($image);
 }
Example #15
0
function draw($lat, $lon, $color = NULL)
{
    global $im;
    global $offset;
    global $dot;
    if ($color == NULL) {
        $color = $dot;
    }
    $pt = getlocationcoords($lat, $long, imagesx($im), imagesy($im));
    ImageRectangle($im, $pt["x"] - $offset, $pt["y"], $pt["x"] + 1 - $offset, $pt["y"] + 1, $dot);
}
Example #16
0
 public function draw($data)
 {
     $img = $this->prepare_image($data);
     // draw filled rectangle first
     if (!empty($data['fill_color'])) {
         imagefilledrectangle($img, $this->padding, $this->padding, $data['perimeter'] / 4, $data['perimeter'] / 4, $this->get_line_color($img, $data['fill_color']));
     }
     // draw 'borders'
     ImageRectangle($img, $this->padding, $this->padding, $data['perimeter'] / 4, $data['perimeter'] / 4, $this->get_line_color($img, $data['line_color']));
     $this->_draw($img);
 }
Example #17
0
function ImageGrid(&$im, $startx, $starty, $width, $height, $xcols, $yrows, &$color)
{
    for ($x = 0; $x < $xcols; $x++) {
        for ($y = 0; $y < $yrows; $y++) {
            $x1 = $startx + $width * $x;
            $x2 = $startx + $width * ($x + 1);
            $y1 = $starty + $height * $y;
            $y2 = $starty + $height * ($y + 1);
            ImageRectangle($im, $x1, $y1, $x2, $y2, $color);
        }
    }
}
Example #18
0
 function IndexAction()
 {
     $str = "23456789ABCDEFGHJKMNPQRSTUVWXYZ";
     $code_str = str_shuffle($str);
     $code = str_split(substr($code_str, 0, 4));
     $_SESSION['VerifyCode'] = strtolower(implode('', $code));
     $width = 115;
     $height = 29;
     $im = ImageCreate($width, $height);
     // 创建图形
     ImageColorAllocate($im, 255, 255, 255);
     // 填充背景颜色为白色
     // 用淡色给图形添加杂色
     for ($i = 0; $i < 100; $i++) {
         $pxcolor = ImageColorAllocate($im, 230, 104, 66);
         ImageSetPixel($im, mt_rand(0, $width), mt_rand(0, $height), $pxcolor);
     }
     // 用深色调绘制边框
     $bordercolor = ImageColorAllocate($im, 255, 255, 255);
     ImageRectangle($im, 0, 0, $width - 1, $height - 1, $bordercolor);
     $offset = rand(10, 30);
     $font = array('View/font/UniversityRomanStd.otf');
     foreach ($code as $char) {
         $textcolor = ImageColorAllocate($im, 230, 104, 106);
         shuffle($font);
         imagettftext($im, 22, rand(-20, 40), $offset, 26, $textcolor, $font[0], $char);
         $offset += $width / 5 - rand(0, 2);
     }
     $code_str = str_shuffle($str);
     $code = str_split(substr($code_str, 0, 5));
     // 干扰字符
     $offset = rand(10, 30);
     foreach ($code as $char) {
         $textcolor = ImageColorAllocate($im, 230, 104, 66);
         shuffle($font);
         imagettftext($im, 8, rand(-20, 40), $offset, 26, $textcolor, $font[0], $char);
         $offset += rand(5, 10);
     }
     // 禁止缓存
     header("pragma:no-cache\r\n");
     header("Cache-Control:no-cache\r\n");
     header("Expires:0\r\n");
     if (ImageTypes() & IMG_PNG) {
         header('Content-Type:image/png');
         ImagePNG($im);
     } elseif (ImageTypes() & IMG_JPEG) {
         header('Content-Type:image/jpeg');
         ImageJPEG($im);
     } else {
         header('Content-Type:image/gif');
         ImageGif($im);
     }
 }
Example #19
0
	/**
	 * Generates a random captcha image
	 *
	 **/
	function display($cachable = false, $urlparams = false)
	{
		$id			= JRequest::getInt( 'captcha-id' , '' );
		$captcha	= Komento::getTable( 'Captcha' , 'KomentoTable' );

		if( ob_get_length() !== false )
		{
			while (@ ob_end_clean());
			if( function_exists( 'ob_clean' ) )
			{
				@ob_clean();
			}
		}

		// clearing the oudated keys.
		$captcha->clear();

		// load the captcha records.
		$captcha->load( $id );

		if( !$captcha->id )
		{
			return false;
		}

		// @task: Generate a very random integer and take only 5 chars max.
		$hash	= JString::substr( md5( rand( 0, 9999 ) ) , 0 , 5 );
	    $captcha->response	= $hash;
		$captcha->store();

	    // Captcha width and height
	    $width	= 100;
	    $height = 20;

	    $image	= ImageCreate( $width , $height );
	    $white	= ImageColorAllocate($image, 255, 255, 255);
	    $black	= ImageColorAllocate($image, 0, 0, 0);
	    $gray	= ImageColorAllocate($image, 204, 204, 204);

	    ImageFill( $image , 0 , 0 , $white );
		ImageString( $image , 5 , 30 , 3 , $hash , $black );
		ImageRectangle( $image , 0 , 0 , $width - 1 , $height - 1 , $gray );
		imageline( $image , 0 , $height / 2 , $width , $height / 2 , $gray );
		imageline( $image , $width / 2 , 0 , $width / 2 , $height , $gray );

		header( 'Content-type: image/jpeg' );
	    ImageJpeg( $image );
	    ImageDestroy($image);
	    exit;
	}
Example #20
0
function kleeja_cpatcha_image()
{
    //Let's generate a totally random string using md5
    $md5_hash = md5(rand(0, 999));
    //I think the bad things in captcha is two things, O and 0 , so let's remove zero.
    $security_code = str_replace('0', '', $md5_hash);
    //We don't need a 32 character long string so we trim it down to 5
    $security_code = substr($security_code, 15, 5);
    //Set the session to store the security code
    $_SESSION["klj_sec_code"] = $security_code;
    //Set the image width and height
    $width = 150;
    $height = 25;
    //Create the image resource
    $image = ImageCreate($width, $height);
    //We are making three colors, white, black and gray
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, rand(0, 100), 0, rand(0, 50));
    $grey = ImageColorAllocate($image, 204, 204, 204);
    //Make the background black
    ImageFill($image, 0, 0, $black);
    //options
    $x = 10;
    $y = 14;
    $angle = rand(-7, -10);
    //Add randomly generated string in white to the image
    if (function_exists('imagettftext')) {
        //
        // We figure a bug that happens when you add font name without './' before it ..
        // he search in the Linux fonts cache , but when you add './' he will know it's our font.
        //
        imagettftext($image, 16, $angle, rand(50, $x), $y + rand(1, 3), $white, './arial.ttf', $security_code);
    } else {
        imagestring($image, imageloadfont('arial.gdf'), $x + rand(10, 15), $y - rand(10, 15), $security_code, $white);
    }
    //kleeja !
    imagestring($image, 1, $width - 35, $height - 10, 'Kleeja', ImageColorAllocate($image, 200, 200, 200));
    //Throw in some lines to make it a little bit harder for any bots to break
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
    imageline($image, 0, $height / 2, $width, $height / 2, $grey);
    imageline($image, $width / 2, 0, $width / 2, $height, $grey);
    //Tell the browser what kind of file is come in
    header("Content-Type: image/png");
    //Output the newly created image in jpeg format
    ImagePng($image);
    //Free up resources
    ImageDestroy($image);
}
Example #21
0
  public function show_image($width = 88, $height = 31) {
    if (isSet($this->tt_font)) {
      if (!file_exists($this->tt_font))
        exit('The path to the true type font is incorrect.');
    }

    if ($this->chars_number < 3)
      exit('The captcha code must have at least 3 characters');

    $string = $this->generate_string();

    $im = ImageCreate($width, $height);

    /* Set a White & Transparent Background Color */
    $bg = ImageColorAllocateAlpha($im, 255, 255, 255, 127); // (PHP 4 >= 4.3.2, PHP 5)
    ImageFill($im, 0, 0, $bg);

    /* Border Color */

    if ($this->border_color) {
      list($red, $green, $blue) = explode(',', $this->border_color);

      $border = ImageColorAllocate($im, $red, $green, $blue);
      ImageRectangle($im, 0, 0, $width - 1, $height - 1, $border);
    }

    $textcolor = ImageColorAllocate($im, 191, 120, 120);

    $y = 24;

    for ($i = 0; $i < $this->chars_number; $i++) {
      $char = $string[$i];

      $factor = 15;
      $x = ($factor * ($i + 1)) - 6;
      $angle = rand(1, 15);

      imagettftext($im, $this->font_size, $angle, $x, $y, $textcolor, $this->tt_font, $char);
    }

    $_SESSION['security_code'] = md5($string);

    /* Output the verification image */
    header("Content-type: image/png");
    ImagePNG($im);

    exit;
  }
Example #22
0
function img($text)
{
    $img_height = 50;
    $img_width = 18;
    $img = imagecreate($img_height, $img_width);
    ImageColorAllocate($img, 255, 255, 255);
    $black = ImageColorAllocate($img, 0, 0, 0);
    for ($i = 0; $i < 10; $i++) {
        ImageString($img, 1, mt_rand(1, $img_height), mt_rand(0, $img_width), "Q", imageColorAllocate($img, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255)));
    }
    ImageRectangle($img, 0, 0, $img_height - 1, $img_width - 1, $black);
    //
    Imagestring($img, 5, 5, 2, $text, imageColorAllocate($img, mt_rand(0, 100), mt_rand(0, 150), mt_rand(0, 200)));
    Imagepng($img);
    ImageDestroy($img);
}
 public function executeSecurityImage(sfWebRequest $request)
 {
     $font = 'monofont.ttf';
     $characters = 6;
     $width = 120;
     $height = 40;
     // code
     /* list all possible characters, similar looking characters and vowels have been removed */
     $possible = '23456789bcdfghjkmnpqrstvwxyz';
     $code = '';
     $i = 0;
     while ($i < $characters) {
         $code .= substr($possible, mt_rand(0, strlen($possible) - 1), 1);
         $i++;
     }
     $_SESSION['securityImage'] = $code;
     //$this->getUser()->setAttribute("securityImage", $code);
     //Set the image width and height
     $width = 100;
     $height = 20;
     //Create the image resource
     $image = ImageCreate($width, $height);
     //We are making three colors, white, black and gray
     $white = ImageColorAllocate($image, 255, 255, 255);
     $black = ImageColorAllocate($image, 0, 0, 0);
     $grey = ImageColorAllocate($image, 204, 204, 204);
     //Make the background black
     ImageFill($image, 0, 0, $black);
     //Add randomly generated string in white to the image
     ImageString($image, 5, 20, 2, $code, $white);
     //Throw in some lines to make it a little bit harder for any bots to break
     ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
     //imageline($image, 0, $height/2, $width, $height/5, $grey);
     imageline($image, $width / 3, 0, $width / 6, $height, $grey);
     imageline($image, $width / 3, $height / 2, $width / 2, $height, $grey);
     imageline($image, $width / 2, $height / 2, $width, $height, $grey);
     //Tell the browser what kind of file is come in
     header("Content-Type: image/jpeg");
     //Output the newly created image in jpeg format
     ImageJpeg($image);
     //Free up resources
     ImageDestroy($image);
     exit;
 }
 function render()
 {
     $this->h = $this->w / 2;
     $im = imagecreatetruecolor($this->w, $this->h);
     $width = $this->w;
     $height = $this->h;
     $center_x = intval($width / 2);
     $center_y = intval($height / 2);
     //gauge color
     $bgcolor = ImageColorAllocate($im, 247, 247, 247);
     $extRing = ImageColorAllocate($im, 214, 214, 214);
     $blueRing = ImageColorAllocate($im, 70, 132, 238);
     $blueRingLine = ImageColorAllocate($im, 106, 114, 127);
     $arrowBody = ImageColorAllocate($im, 228, 114, 86);
     $arrowLine = ImageColorAllocate($im, 207, 74, 42);
     $redArc = ImageColorAllocate($im, 220, 57, 18);
     $yellowArc = ImageColorAllocate($im, 255, 153, 0);
     $black = ImageColorAllocate($im, 0, 0, 0);
     $white = ImageColorAllocate($im, 255, 255, 255);
     $gray = ImageColorAllocate($im, 190, 190, 190);
     $fontArial = PATH_THIRDPARTY . 'html2ps_pdf/fonts/arial.ttf';
     ImageFilledRectangle($im, 0, 0, $width - 1, $height - 1, $white);
     ImageRectangle($im, 0, 0, $width - 1, $height - 1, $gray);
     //center coords
     $cX = intval($this->w / 2);
     //$cX = intval($this->w /4);
     $cY = intval($this->h / 2);
     //diameter for gauge
     $diameter = intval($this->h * 4 / 5);
     $this->renderGauge($im, $cX, $cY, $diameter);
     /*
     //center coords
     $cX = intval($this->w * 3/4);
     $cY = intval($this->h /2);
     
     //diameter for gauge
     $diameter = intval( $this->h * 4/5 );
     
     $this->renderGauge($im, $cX, $cY, $diameter);
     */
     Header("Content-type: image/png");
     ImagePng($im);
 }
 function display($db_object, $common, $user_id, $default, $error_msg, $learning, $post_var)
 {
     $width = 340;
     $height = 220;
     //	$labelfont = '2';
     $labeltitlefont = '3';
     $image = ImageCreate($width, $height);
     while (list($kk, $vv) = @each($post_var)) {
         ${$kk} = $vv;
     }
     $bgcolor = ImageColorAllocate($image, 0xffffff, 0xffffff, 0xffffff);
     $border = ImageColorAllocate($image, 0x0, 0x0, 0x0);
     $border1 = ImageColorAllocate($image, 0xcccccc, 0x0, 0x0);
     $border2 = ImageColorAllocate($image, 0x0, 0xcccccc, 0x0);
     ImageRectangle($image, 40, 20, 240, 160, $border);
     ImageString($image, $labelfont, 15, 20, "100%", $border);
     ImageString($image, $labelfont, 20, 55, "75%", $border);
     ImageString($image, $labelfont, 20, 90, "50%", $border);
     ImageString($image, $labelfont, 20, 125, "25%", $border);
     ImageString($image, $labelfont, 20, 155, "0%", $border);
     $fdate = $learning->changedate_display($from_date);
     $tdate = $learning->changedate_display($to_date);
     $days = $error_msg['cDays'] . " {$fdate} " . $error_msg['cTo'] . " {$tdate} ";
     $avg_comp = 160 - 140 / 100 * $avg;
     $avg = round($avg, 2);
     ImageStringUp($image, $labeltitlefont, 5, 110, $error_msg['cResults'], $border);
     ImageString($image, $labeltitlefont, 245, 20, $error_msg['cCommitment'], $border);
     ImageString($image, $labeltitlefont, 50, 170, "{$days}", $border);
     ImageString($image, $labeltitlefont, 50, 200, $error_msg['cCTimelyCompletionofActivities'], $border);
     ImageString($image, $labeltitlefont, 50, 185, $error_msg['cAverage'], $border);
     ImageString($image, $labeltitlefont, 115, 185, $avg, $border);
     ImageLine($image, 240, 20, 40, 160, $border1);
     //COMMITMENT LINE
     ImageLine($image, 240, $avg_comp, 40, 160, $border2);
     //AVERAGE COMPLETION
     ImageString($image, $labeltitlefont, 245, $avg_comp, $error_msg['cAccomplishment'], $border);
     header("Content-type: image/png");
     // or "Content-type: image/png"
     Imagepng($image);
     // or imagepng($image)
     ImageDestroy($image);
 }
Example #26
0
function abatly_captcha()
{
    $md5_hash = md5(rand(0, 999));
    $security_code = str_replace('0', '', $md5_hash);
    $security_code = substr($security_code, 15, 5);
    $_SESSION["security_code"] = $security_code;
    $width = 128;
    $height = 40;
    $image = ImageCreate($width, $height);
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, rand(0, 100), 0, rand(0, 50));
    $grey = ImageColorAllocate($image, 204, 204, 204);
    $red = imagecolorallocatealpha($image, 255, 0, 0, 75);
    $green = imagecolorallocatealpha($image, 0, 255, 0, 75);
    $blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
    imagefilledrectangle($image, 0, 0, $width, $height, $white);
    imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $red);
    imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $green);
    imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $blue);
    imagefilledrectangle($image, 0, 0, $width, 0, $black);
    imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black);
    imagefilledrectangle($image, 0, 0, 0, $height - 1, $black);
    imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black);
    ImageFill($image, 0, 0, $black);
    $x = 20;
    $y = 24;
    $angle = rand(-7, -10);
    if (function_exists('imagettftext')) {
        imagettftext($image, 20, $angle, rand(20, $x), $y + rand(1, 3), $black, 'arial.ttf', $security_code);
    } else {
        imagestring($image, imageloadfont('arial.gdf'), $x + rand(10, 15), $y - rand(10, 15), $security_code, $white);
    }
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $black);
    imageline($image, $width / 2, 0, $width / 2, $height, $black);
    header("Content-Type: image/png");
    ImagePng($image);
    ImageDestroy($image);
}
Example #27
0
 function gen_img()
 {
     $this->img_width = 15 * $this->length;
     if (function_exists('imagecreatetruecolor')) {
         $img = imagecreatetruecolor($this->img_width, $this->img_height);
         $_SESSION['hg_verifycode'] = $this->code;
         $white = ImageColorAllocate($img, 255, 255, 255);
         $black = ImageColorAllocate($img, 0, 0, 0);
         $gray = imagecolorallocate($img, 200, 200, 200);
         ImageRectangle($img, 1, 1, $this->img_width - 1, $this->img_height - 1, $black);
         imagefill($img, $this->img_width, $img->height, $white);
         for ($i = 0; $i < 200; $i++) {
             $rand_color = imagecolorallocate($img, mt_rand(180, 255), mt_rand(180, 255), mt_rand(180, 255));
             imagesetpixel($img, mt_rand() % $this->img_width, mt_rand() % $this->img_height, $rand_color);
         }
         for ($i = 0; $i < $this->length; $i++) {
             $rand_color = imagecolorallocate($img, mt_rand(0, 180), mt_rand(0, 180), mt_rand(0, 180));
             imagestring($img, 5, 1 + $i * 15, 1, $this->code[$i], $rand_color);
         }
         imagejpeg($img);
         header("Content-type: image/jpeg");
     }
 }
Example #28
0
 function gen_img()
 {
     $this->img_width = 15 * $this->length + 10;
     if (function_exists('imagecreatetruecolor')) {
         $font = './arial.ttf';
         //字体可更换,中文需要字体支持
         if (!is_file($font)) {
             exit($font . '字体文件不存在');
         }
         $img = imagecreatetruecolor($this->img_width, $this->img_height);
         $_SESSION['session_code'] = $this->code;
         $white = ImageColorAllocate($img, 255, 255, 255);
         $black = ImageColorAllocate($img, 0, 0, 0);
         $gray = imagecolorallocate($img, 200, 200, 200);
         ImageRectangle($img, 1, 1, $this->img_width - 1, $this->img_height - 1, $black);
         imagefill($img, $this->img_width, $img->height, $white);
         for ($i = 0; $i < 200; $i++) {
             $rand_color = imagecolorallocate($img, mt_rand(180, 255), mt_rand(180, 255), mt_rand(180, 255));
             imagesetpixel($img, mt_rand() % $this->img_width, mt_rand() % $this->img_height, $rand_color);
         }
         $xs = array(5, 12, 30, 38, 58);
         for ($i = 0; $i < $this->length; $i++) {
             $x = $xs[$i];
             if ($i % 2 == 0) {
                 $y = 30;
                 $ag = 15;
             } else {
                 $y = 30;
                 $ag = -30;
             }
             $rand_color = imagecolorallocate($img, mt_rand(0, 200), mt_rand(0, 180), mt_rand(0, 180));
             imagettftext($img, 22, $ag, $x, $y, $rand_color, $font, $this->code[$i]);
         }
         imagejpeg($img);
         header("Content-type: image/jpeg");
     }
 }
Example #29
0
function drawRating()
{
    if (isset($_GET['rating'])) {
        $rating = $_GET['rating'];
    } else {
        $rating = 0;
    }
    if (isset($_GET['width'])) {
        $width = $_GET['width'];
    } else {
        $width = 170;
    }
    if (isset($_GET['height'])) {
        $height = $_GET['height'];
    } else {
        $height = 5;
    }
    $ratingbar = $rating / 100 * $width - 2;
    $image = imagecreate($width, $height) or die("Cannot Create image");
    $fill = ImageColorAllocate($image, 0, 255, 0);
    if ($rating > 49) {
        $fill = ImageColorAllocate($image, 255, 255, 0);
    }
    if ($rating > 74) {
        $fill = ImageColorAllocate($image, 255, 128, 0);
    }
    if ($rating > 89) {
        $fill = ImageColorAllocate($image, 255, 0, 0);
    }
    $back = ImageColorAllocate($image, 205, 205, 205);
    $border = ImageColorAllocate($image, 0, 0, 0);
    ImageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $back);
    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $fill);
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border);
    imagePNG($image);
    imagedestroy($image);
}
Example #30
0
function blah($cstr)
{
    $old_security_string = $cstr;
    $security_string = "";
    for ($i = 0; $i <= strlen($old_security_string) - 1; $i++) {
        $str = substr($old_security_string, $i, 1);
        if ($i % 2 == 0) {
            $str = strtoupper($str);
        }
        $security_string = $security_string . $str . ' ';
    }
    $_SESSION["captchaStr"] = $old_security_string;
    $width = 100;
    $height = 30;
    $image = ImageCreate($width, $height);
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 0, 0, 0);
    $grey = ImageColorAllocate($image, 120, 120, 120);
    $red = ImageColorAllocate($image, 132, 12, 4);
    ImageFill($image, 5, 5, $grey);
    $font = 8;
    imagestring($image, 15, 12, 8, $security_string, $white);
    //ImageString($image, $font, 12, 3, $security_string, $white);
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $black);
    /*
    	$line = imagecolorallocate($image,233,239,239); 
    
    	imageline($image,0,0,39,29,$line);
    	imageline($image,60,0,40,29,$line);
    	imageline($image,40,0,64,29,$line);
    	imageline($image,80,0,94,29,$line);
    */
    header("Content-Type: image/png");
    ImagePng($image);
    ImageDestroy($image);
}