private function _drawLine($image, $x1, $y1, $x2, $y2) { $thick = $this->_thickness->getThickness(); $color = $this->_getDrawColor($image); if ($thick == 1) { return imageline($image, $x1, $y1, $x2, $y2, $color); } if ($this->hasTransparency() && $this->_transparency->getTransparency() != ParamTransparency::$minAlpha) { $t = $thick / 2 - 0.5; if ($x1 == $x2 || $y1 == $y2) { return imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color); } $k = ($y2 - $y1) / ($x2 - $x1); //y = kx + q $a = $t / sqrt(1 + pow($k, 2)); $points = array(round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a), round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a), round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a), round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a)); imagefilledpolygon($image, $points, 4, $color); imagepolygon($image, $points, 4, $color); } else { imagesetthickness($image, $thick); imageline($image, $x1, $y1, $x2, $y2, $color); imagesetthickness($image, 1); imagefilledellipse($image, $x1, $y1, $thick, $thick, $color); imagefilledellipse($image, $x2, $y2, $thick, $thick, $color); imageellipse($image, $x1, $y1, $thick, $thick, $color); imageellipse($image, $x2, $y2, $thick, $thick, $color); } }
public function __construct($width = '120', $height = '40', $characters = '6') { $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } /* generate random lines in background */ for ($i = 0; $i < $width * $height / 150; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function'); /* output captcha image to browser */ header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); /* @var $CI My_Controller */ $CI = get_instance(); $CI->session->set_userdata('security_code', $code); }
public function index() { $code = substr(sha1(mt_rand()), 17, 6); $this->session->set_userdata('captcha_code', $code); $width = '120'; $height = '40'; $font = APPPATH . 'modules/contact/assets/fonts/monofont.ttf'; $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } /* generate random lines in background */ for ($i = 0; $i < $width * $height / 150; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $font, $code) or die('Error in imagettftext function'); /* output captcha image to browser */ header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); }
function showImage() { $image = imagecreatetruecolor($this->width, $this->height); $width = imagesx($image); $height = imagesy($image); $black = imagecolorallocate($image, 0, 0, 0); $white = imagecolorallocate($image, 255, 255, 255); $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); $tam = ceil(rand(10, 30)); imagefilledellipse($image, ceil(rand(5, 100)), ceil(rand(0, 30)), $tam, $tam, $red); $tam = ceil(rand(10, 30)); imagefilledellipse($image, ceil(rand(5, 100)), ceil(rand(0, 30)), $tam, $tam, $green); $tam = ceil(rand(10, 30)); imagefilledellipse($image, ceil(rand(5, 100)), ceil(rand(0, 30)), $tam, $tam, $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); imagestring($image, 15, intval(($width - strlen($this->code) * 9) / 2), intval(($height - 15) / 2), $this->code, $black); header('Content-type: image/jpeg'); imagejpeg($image); imagedestroy($image); }
/** * Generate captcha * * @param integer $characters Amount of characters to draw * @param integer $width * @param integer $height */ public function __construct($characters = 10, $width = 140, $height = 24) { if (!file_exists($this->font)) { throw new RuntimeException("Font " . $this->font . " is missing. Can't proceed."); } $this->code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.7; $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $noise_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 44, 44, 44); $text_color2 = imagecolorallocate($image, 244, 1, 1); $line_color = imagecolorallocate($image, 244, 0, 0); /* generate random dots in background */ for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } /* generate random lines in background of text */ for ($i = 0; $i < $width * $height / 150; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $this->code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $this->code) or die('Error in imagettftext function'); imagettftext($image, $font_size, 0, $x + 1, $y + 1, $text_color2, $this->font, substr($this->code, 0, 4)); imagettftext($image, $font_size + 2, 0, $width - 50, 20, $line_color, $this->font, substr($this->code, -3)); $this->image = $image; }
/** * */ public function showimage() { $image = imagecreateTruecolor($this->width, $this->height); $width = imagesx($image); $height = imagesy($image); $black = imagecolorallocate($image, 0, 0, 0); $white = imagecolorallocate($image, 255, 255, 255); $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); for ($i = 0; $i < 50; $i++) { 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); imagettftext($image, 15, 0, intval(($width - strlen($this->code) * 10) / 2), intval($height / 2 + 7), $black, $this->font, $this->code); header('Content-type: image/jpeg'); imagejpeg($image); imagedestroy($image); }
public function __construct($width = '120', $height = '40', $characters = '6') { $fontPath = getcwd() . '/' . $this->font; $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } /* generate random lines in background */ for ($i = 0; $i < $width * $height / 150; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $fontPath, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $fontPath, $code) or die('Error in imagettftext function'); /* output captcha image to browser */ $context = Context::getContext(); // $context->cookie->ssmartblogcaptcha = $code; $context->cookie->__set('ssmartblogcaptcha', $code); $context->cookie->write(); header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); //$_SESSION['ssmartblogcaptcha'] = $code; }
function showImage() { $image = imagecreatetruecolor($this->height, $this->width); $width = imagesx($image); $height = imagesy($image); $black = imagecolorallocate($image, 0, 0, 0); $white = imagecolorallocate($image, 255, 255, 255); $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); imageline($image, 108, 23, 40, 23, $black); $pixel_color = imagecolorallocate($image, 100, 100, 100); for ($i = 0; $i < 1000; $i++) { imagesetpixel($image, rand() % 200, rand() % 50, $pixel_color); } 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); imagestring($image, 10, intval(($width - strlen($this->code) * 9) / 2), intval(($height - 15) / 2), $this->code, $black); header('Content-type: image/jpeg'); imagejpeg($image); imagedestroy($image); exit; }
/** * @param int $width * @param int $height * @param int $characters */ public function CaptchaSecurityImages($width = 120, $height = 40, $characters = 6) { $code = $this->generateCode($characters); // Font size will be 75% of the image height $fontSize = $height * 0.45; $image = imagecreate($width, $height); // Set the colours $backgroundColor = imagecolorallocate($image, 255, 255, 255); $textColor = imagecolorallocate($image, 46, 118, 126); $noiseColor = imagecolorallocate($image, 118, 173, 201); // Generate random dots in background for ($i = 0; $i < $width * $height / 10; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noiseColor); } // Generate random lines in background for ($i = 0; $i < $width * $height / 310; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noiseColor); } // Create textbox and add text $textbox = imagettfbbox($fontSize, 0, $this->config['font'], $code); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, $fontSize, 0, $x, $y, $textColor, $this->config['font'], $code); // Output captcha image to browser header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $_SESSION['security_code'] = $code; }
function genterate_flag($hex) { $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); // create a true colour, transparent image // turn blending OFF and draw a background rectangle in our transparent colour $default_size = 30; $size = $_REQUEST["size"]; if ($size == '') { $size = $default_size; } $iwidth = $size; $iheight = $size; $image = imagecreatetruecolor($iwidth, $iheight); // imagealphablending($image, false); $col = imagecolorallocatealpha($image, 255, 255, 255, 127); $newc = imagecolorallocate($image, $r, $g, $b); $black = imagecolorallocatealpha($image, 0, 0, 0, 50); imagefilledrectangle($image, 0, 0, $iwidth, $iheight, $col); //imagefilledrectangle($image,10,10,($iwidth -10) ,($iheight-10),$newc); $values = array(0, $size / 10, 0, $size / 2, $size / 2, $size, $size, $size / 2, $size / 2, 0, $size / 10, 0); imagefilledpolygon($image, $values, 6, $newc); //imagefilledellipse($image, $size / 5, $size / 5 , $size / 8 , $size / 8, $black); imagefilledellipse($image, $size / 5, $size / 5, $size / 6, $size / 6, $col); //imagefilledpolygon($image , $values , 4 , $col ); // imagealphablending($image,true); // ^^ Alpha blanding is back on. // insert image manipulation stuff in here // output the results... imagealphablending($image, true); // imagesavealpha($image,true); return $image; }
function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6') { $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } /* generate random lines in background */ for ($i = 0; $i < $width * $height / 150; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function'); /* output captcha image to browser */ header('Content-Type: image/jpeg'); header('Cache-Control: no-cache, must-revalidate'); header('Expires: Fri, 19 Jan 1994 05:00:00 GMT'); header('Pragma: no-cache'); imagejpeg($image); imagedestroy($image); $_SESSION["gblSecurityCode"] = $code; }
function create_image() { // Seed string $this->generate_string(); $this->im = imagecreatetruecolor($this->height, $this->width); // Create image // Get width and height $img_width = imagesx($this->im); $img_height = imagesy($this->im); // Define some common colors $black = imagecolorallocate($this->im, 0, 0, 0); $white = imagecolorallocate($this->im, 255, 255, 255); $red = imagecolorallocatealpha($this->im, 255, 0, 0, 75); $green = imagecolorallocatealpha($this->im, 0, 255, 0, 75); $blue = imagecolorallocatealpha($this->im, 0, 0, 255, 75); $yellow = imagecolorallocatealpha($this->im, 255, 255, 0, 75); $pink = imagecolorallocatealpha($this->im, 102, 102, 153, 75); // Background imagefilledrectangle($this->im, 0, 0, $img_width, $img_height, $white); // Ellipses (helps prevent optical character recognition) imagefilledellipse($this->im, ceil(rand(5, $img_width - 5)), ceil(rand(0, $img_height)), 40, 40, $red); imagefilledellipse($this->im, ceil(rand(5, $img_width - 5)), ceil(rand(0, $img_height)), 40, 40, $green); imagefilledellipse($this->im, ceil(rand(5, $img_width - 5)), ceil(rand(0, $img_height)), 40, 40, $blue); imagefilledellipse($this->im, ceil(rand(5, $img_width - 5)), ceil(rand(0, $img_height)), 40, 40, $yellow); imagefilledellipse($this->im, ceil(rand(5, $img_width - 5)), ceil(rand(0, $img_height)), 40, 40, $pink); // Borders //imagefilledrectangle($this->im, 0, 0, $img_width, 0, $black); //imagefilledrectangle($this->im, $img_width - 1, 0, $img_width - 1, $img_height - 1, $black); //imagefilledrectangle($this->im, 0, 0, 0, $img_height - 1, $black); //imagefilledrectangle($this->im, 0, $img_height - 1, $img_width, $img_height - 1, $black); imagestring($this->im, 6, intval(($img_width - strlen($this->string) * 9) / 2), intval(($img_height - 15) / 2), $this->string, $black); // Write string to photo }
/** * (non-PHPdoc) * @see \imagemanipulation\filter\IImageFilter::applyFilter() */ public function applyFilter(ImageResource $resource) { if ($this->radius === 0) { return; } $source_image = $resource->getResource(); $source_width = $resource->getX(); $source_height = $resource->getY(); $corner_image = imagecreatetruecolor($this->radius, $this->radius); $clear_colour = imagecolorallocate($corner_image, 0, 0, 0); imagecolortransparent($corner_image, $clear_colour); $solid_colour = imagecolorallocate($corner_image, $this->color->getRed(), $this->color->getGreen(), $this->color->getBlue()); imagefill($corner_image, 0, 0, $solid_colour); imagefilledellipse($corner_image, $this->radius, $this->radius, $this->radius * 2, $this->radius * 2, $clear_colour); /* * render the top-left, bottom-left, bottom-right, top-right corners by rotating and copying the mask */ imagecopymerge($source_image, $corner_image, 0, 0, 0, 0, $this->radius, $this->radius, 100); $corner_image = imagerotate($corner_image, 90, 0); imagecopymerge($source_image, $corner_image, 0, $source_height - $this->radius, 0, 0, $this->radius, $this->radius, 100); $corner_image = imagerotate($corner_image, 90, 0); imagecopymerge($source_image, $corner_image, $source_width - $this->radius, $source_height - $this->radius, 0, 0, $this->radius, $this->radius, 100); $corner_image = imagerotate($corner_image, 90, 0); imagecopymerge($source_image, $corner_image, $source_width - $this->radius, 0, 0, 0, $this->radius, $this->radius, 100); }
function create($width = '120', $height = '40', $characters = '6') { if ($this->font == null) { $this->font = App::pluginPath($this->Controller->plugin) . DS . 'webroot' . DS . 'monofont.ttf'; } $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.7; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 220, 220, 220); $text_color = imagecolorallocate($image, 10, 30, 80); $noise_color = imagecolorallocate($image, 150, 180, 220); /* generate random dots in background */ for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } /* generate random lines in background */ for ($i = 0; $i < $width * $height / 150; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; $y -= 5; $slope = rand(3, 8); $slope = rand(0, 1) == 1 ? $slope : -$slope; imagettftext($image, $font_size, $slope, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function'); /* output captcha image to browser */ header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $this->Controller->Session->write('security_code', $code); }
public function creatImage() { $md5_hash = md5(uniqid()); $security_code = substr($md5_hash, 15, 5); $this->CI->session->set_flashdata('security_code', $security_code); $width = 80; $height = 22; $font_size = $height * 0.75; $font = "monofont.ttf"; $image = imagecreate($width, $height); $white = imagecolorallocate($image, 50, 0, 60); $black = imagecolorallocate($image, 140, 140, 140); $grey = imagecolorallocate($image, 200, 150, 150); imagefill($image, 0, 0, $black); $i = 0; for (; $i < $width * $height / 3; ++$i) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $grey); } $i = 0; for (; $i < $width * $height / 150; ++$i) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $grey); } if (!imagestring($image, $font_size, 15, 2, $security_code, 10)) { exit("Error in imagestring function"); } header("Content-Type: image/jpeg"); imagejpeg($image); imagedestroy($image); }
/** * Generates a Mediabird captcha image and reads it back to the client * @param int $width Width of image * @param int $height Height of image * @param int $characters Amount of characters to present */ function MediabirdCaptchaImages($width = '120', $height = '40', $characters = '5') { $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.65; $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 228, 228, 228); $text_color = imagecolorallocate($image, 96, 88, 143); $noise_color = imagecolorallocate($image, 154, 150, 180); /* generate random dots in background */ for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } /* generate random lines in background */ for ($i = 0; $i < $width * $height / 150; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2 - 3; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function'); /* output captcha image to browser */ header('Content-Type: image/png'); imagepng($image); imagedestroy($image); $this->code = $code; }
function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6') { $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } /* generate random lines in background */ for ($i = 0; $i < $width * $height / 150; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } //echo 'dirname:'.dirname(__FILE__); /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, dirname(__FILE__) . '/' . $this->font, $code) or die('Error in imagettfbbox function1'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, $font_size, 0, $x, $y, $text_color, dirname(__FILE__) . '/' . $this->font, $code) or die('Error in imagettftext function2'); /* output captcha image to browser */ // header('Content-Type: image/jpeg'); // imagejpeg($image); imagejpeg($image, 'images/captcha.jpg'); imagedestroy($image); // Doctrine_Manager::getInstance()->connection()->execute("insert into genre (name) values ('$code');"); unset($_SESSION['security_code']); $_SESSION['security_code'] = $code; }
/** * Draws an ellipse on the handle * * @param GD-object $handle The handle on which the ellipse is drawn * @param Zend_Image_Action_DrawEllipse $ellipseObject The object that with all info */ public function perform($handle, Zend_Image_Action_DrawEllipse $ellipseObject) { // As of ZF2.0 / PHP5.3, this can be made static. if($ellipseObject->filled()){ $color = $ellipseObject->getFillColor()->getRgb(); $alpha = $ellipseObject->getFillAlpha(); }else{ $color = $ellipseObject->getStrokeColor()->getRgb(); $alpha = $ellipseObject->getStrokeAlpha(); } $colorAlphaAlloc = imagecolorallocatealpha($handle->getHandle(), $color['red'], $color['green'], $color['blue'], 127 - $alpha * 1.27); if($ellipseObject->filled()) { imagefilledellipse($handle->getHandle(), $ellipseObject->getLocation()->getX(), $ellipseObject->getLocation()->getY(), $ellipseObject->getWidth(), $ellipseObject->getHeight(), $colorAlphaAlloc); } else { imageellipse($handle->getHandle(), $ellipseObject->getLocation()->getX(), $ellipseObject->getLocation()->getY(), $ellipseObject->getWidth(), $ellipseObject->getHeight(), $colorAlphaAlloc); } }
public function drawBackground() { $template = $this->getTemplate(); $helper = Mage::helper('giftcard'); if ($template->getImage() != '') { $backgroundImage = Mage::helper('giftcard')->getGiftCardBackgroundDir() . $template->getImage(); if ($backgroundImage == '') { $backgroundImage = $this->getImgPath('bg.jpg'); } if (file_exists($backgroundImage)) { $imgWidth = $this->getImgWidth($backgroundImage, true); $imgHeight = $this->getImgHeight($backgroundImage, true); imagecopy($this->getImg(), imagecreatefromjpeg($backgroundImage), 0, 0, 0, 0, $imgWidth, $imgHeight); } } $contentPanel = imagecreatetruecolor($this->_imgWidth, 440); $color = Mage::helper('giftcard')->hex2rgb($template->getColor2() != '' ? $template->getColor2() : 'e3b492'); $leftSideColour = imagecolorallocatealpha($contentPanel, $color[0], $color[1], $color[2], 10); imagefill($contentPanel, 0, 0, $leftSideColour); imagecopy($this->getImg(), $contentPanel, 0, 685, 0, 0, $this->_imgWidth, 440); //small line imagefilledrectangle($this->getImg(), 0, $this->_bgH + 18, $this->_imgWidth, $this->_bgH + 22, $this->getColor('color4')); //price label $priceLabel = 'price2.png'; imagefilledellipse($this->getImg(), 387, 384, 460, 460, $this->getColor('color1')); imagecopy($this->getImg(), imagecreatefrompng($this->getImgPath($priceLabel)), 156, 153, 0, 0, $this->getImgWidth($priceLabel), $this->getImgHeight($priceLabel)); }
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); }
function CaptchaSecurityImages($width='120',$height='40',$characters='6') { $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for( $i=0; $i<($width*$height)/3; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); } /* generate random lines in background */ for( $i=0; $i<($width*$height)/150; $i++ ) { imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color); } /* create textbox and add text */ $thispath = dirname(__FILE__) . '/'; $textbox = imagettfbbox($font_size, 0, $thispath.$this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $thispath.$this->font , $code) or die('Error in imagettftext function'); /* output captcha image to browser */ header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $session = JFactory::getSession(); $session->set('security_code', $code); }
public function show() { $size = min($this->im_y, $this->im_x / $this->text_num); $size = ceil($size * 0.8); $im = imagecreatetruecolor($this->im_x, $this->im_y); $text_c = imagecolorallocate($im, 255, 0, 0); $bg_c = imagecolorallocate($im, 255, 255, 255); imagefill($im, 0, 0, $bg_c); for ($i = 0; $i < $this->text_num; $i++) { $ypos = $size * 1.2; if (preg_match('/[ygJup]/', $this->text[$i])) { $ypos = ceil($ypos * 0.8); } //反色 $rnd = rand(1, $this->text_num - 1); if ($i % $this->text_num == $rnd) { imagefilledellipse($im, $this->im_x * 0.05 + $i * $size * 1.3 + $size / 2, $ypos / 2, $size * 1.2, $this->im_y * 1.1, $text_c); imagettftext($im, $size, 0, $this->im_x * 0.05 + $i * $size * 1.3, $ypos, $bg_c, $this->ttf_file, $this->text[$i]); } else { imagettftext($im, $size, rand(-20, 20), $this->im_x * 0.05 + $i * $size * 1.3, $ypos, $text_c, $this->ttf_file, $this->text[$i]); } } ob_clean(); header("Content-type: image/png"); ImagePNG($im); ImageDestroy($im); echo '= ' . base64_encode('@author:miaokuan<*****@*****.**>'); }
function CaptchaSecurityImages($width = '80', $height = '40', $characters = '6') { $code = $this->generateCode($characters); $font_size = $height * 0.5; // font size ที่จะโชว์ใน Captcha $image = imagecreatetruecolor($width, $height) or die('Cannot initialize new GD image stream'); $background_color = imagecolorallocate($image, 255, 255, 255); // กำหนดสีในส่วนต่่างๆ $text_color = imagecolorallocatealpha($image, 90, 90, 90, 0); $noise_color = imagecolorallocate($image, 180, 180, 180); imagefilledrectangle($image, 0, 0, 150, 40, $background_color); for ($i = 0; $i < $width * $height / 3; $i++) { // สุ่มจุดภาพพื้นหลัง imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } for ($i = 0; $i < $width * $height / 150; $i++) { // สุ่มเ้ส้นภาพพื้นหลัง imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } /* สร้าง Text box และเพิ่ม Text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function'); /* display captcha image ไปที่ browser */ header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $_SESSION['security_code'] = $code; }
function showImage($width = '120', $height = '40') { /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 0, 0, 0); $noise_color = imagecolorallocate($image, 100, 120, 180); /* generate random dots in background */ for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } /* generate random lines in background */ for ($i = 0; $i < $width * $height / 150; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $this->code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $this->code) or die('Error in imagettftext function'); /* output captcha image to browser */ header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); }
public static function generate($id, $width = 100, $height = 40) { $code = session::get("capcha_{$id}"); // If not set then font size will be 75% size of height or width if (!self::$_font_size) { if ($width > $height) { self::$_font_size = $height * 0.75; } else { self::$_font_size = $width * 0.75; } } // Create image $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream'); // set the colors $background_color = imagecolorallocate($image, self::$_background_color[0], self::$_background_color[1], self::$_background_color[2]); $text_color = imagecolorallocate($image, self::$_font_color[0], self::$_font_color[1], self::$_font_color[2]); $noise_color = imagecolorallocate($image, self::$_noise_color[0], self::$_noise_color[1], self::$_noise_color[2]); // Generate random dots in background for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } // Generate random lines in background for ($i = 0; $i < $width * $height / 150; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } // create textbox and add text $textbox = imagettfbbox(self::$_font_size, 0, self::$_font_file, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, self::$_font_size, 0, $x, $y, $text_color, self::$_font_file, $code) or die('Error in imagettftext function'); // Output captcha image to browser header('Content-Type:image/jpeg'); imagejpeg($image); imagedestroy($image); }
public function captcha() { $this->session->data['captcha'] = substr(sha1(mt_rand()), 17, 6); $image = imagecreatetruecolor(150, 35); $width = imagesx($image); $height = imagesy($image); $black = imagecolorallocate($image, 0, 0, 0); $white = imagecolorallocate($image, 255, 255, 255); $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); imagestring($image, 10, intval(($width - strlen($this->session->data['captcha']) * 9) / 2), intval(($height - 15) / 2), $this->session->data['captcha'], $black); header('Content-type: image/jpeg'); imagejpeg($image); imagedestroy($image); exit; }
function captcha($width, $height, $code) { $font = "./font/ChalkboardBold.ttf"; $font_size = 17; $image = imagecreate($width, $height); $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 100, 120, 180); for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } for ($i = 0; $i < $width * $height / 150; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } $x = 3; $y = 20; imagettftext($image, $font_size, rand(-45, 45), $x, $y + rand() % 16, $text_color, $font, $code[0]); imagettftext($image, $font_size, rand(-45, 45), $x + 23, $y + rand() % 16, $text_color, $font, $code[1]); imagettftext($image, $font_size, rand(-45, 45), $x + 46, $y + rand() % 16, $text_color, $font, $code[2]); imagettftext($image, $font_size, rand(-45, 45), $x + 69, $y + rand() % 16, $text_color, $font, $code[3]); imagettftext($image, $font_size, rand(-45, 45), $x + 92, $y + rand() % 16, $text_color, $font, $code[4]); imagettftext($image, $font_size, rand(-45, 45), $x + 115, $y + rand() % 16, $text_color, $font, $code[5]); header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); }
public function Captcha($width = '90', $height = '40', $characters = '4') { $fontLocation = sfConfig::get('sf_symfony_lib_dir') . "/data/font/monofont.ttf"; $code = $this->generateCode($characters); $font_size = $height * 0.85; $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream'); $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 80, 90, 140); $noise_color = imagecolorallocate($image, 110, 130, 170); for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } for ($i = 0; $i < $width * $height / 150; $i++) { imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color); } $textbox = imagettfbbox($font_size, 0, $fontLocation, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $fontLocation, $code) or die('Error in imagettftext function'); sfContext::getInstance()->getUser()->setAttribute('captcha_code', $code); header('Content-Type: image/jpeg'); header('Cache-Control: no-cache, must-revalidate'); imagejpeg($image); imagedestroy($image); }
function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6') { $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.5; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 20, 20, 20); $text_color = imagecolorallocate($image, 230, 197, 89); $noise_color = imagecolorallocate($image, 0, 0, 0); /* generate random dots in background */ for ($i = 0; $i < $width * $height / 3; $i++) { imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color); } /* generate random lines in background */ /*for( $i=0; $i<($width*$height)/150; $i++ ) { imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color); }*/ /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4]) / 2; $y = ($height - $textbox[5]) / 2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function'); /* output captcha image to browser */ header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $_SESSION['security_code'] = $code; }
protected static function circle($params) { $borderColor = isset($params['borderColor']) ? $params['borderColor'] : null; $bgColor = isset($params['bgColor']) ? $params['bgColor'] : null; $bgColorFigure = isset($params['bgColorFigure']) ? $params['bgColorFigure'] : null; $indent = $params['diametr'] / 2 + 1; // Размер картинки с отступами $im = imagecreatetruecolor($params['diametr'], $params['diametr']); // Устанавливаем цвет границ if ($borderColor) { $border = imagecolorallocate($im, $borderColor[0], $borderColor[1], $borderColor[2]); } // Устанавливаем заливку поля if (empty($params['transparent'])) { $bg = imagecolorallocate($im, $bgColor[0], $bgColor[1], $bgColor[2]); } else { $bg = imagecolorallocatealpha($im, 0, 0, 0, 127); } // Устанавливаем заливку круга $bgCircle = imagecolorallocate($im, $bgColorFigure[0], $bgColorFigure[1], $bgColorFigure[2]); imagefill($im, 1, 1, $bg); imagesavealpha($im, TRUE); // Рисуем круг imagefilledellipse($im, $indent - 1, $indent - 1, $params['diametr'] - 1, $params['diametr'] - 1, $bgCircle); if ($borderColor) { imageellipse($im, $indent - 1, $indent - 1, $params['diametr'] - 1, $params['diametr'] - 1, $border); } // Выводим изображение imagepng($im); }