示例#1
0
文件: verify.php 项目: topstdio/xnova
function createAuthNumImg($randStr, $imgW = 100, $imgH = 40, $fontName)
{
    $image = imagecreate($imgW, $imgH);
    $color_white = imagecolorallocate($image, 255, 255, 255);
    $color_gray = imagecolorallocate($image, 228, 228, 228);
    $color_black = imagecolorallocate($image, 255, 102, 204);
    $color_radom = imagecolorallocate($image, rand(1, 200), rand(1, 200), rand(10, 250));
    for ($i = 0; $i < 2000; $i++) {
        $c = imagecolorallocate($image, rand(1, 200), rand(1, 200), rand(10, 250));
        imagesetpixel($image, mt_rand(0, $imgW), mt_rand(0, $imgH), $c);
        //Ìí¼ÓÔÓµã
    }
    imagerectangle($image, 0, 0, $imgW - 1, $imgH - 1, $color_gray);
    imagettftext($image, 50, mt_rand(-2, 2), rand(0, 20), 50, $color_radom, $fontName, $randStr);
    for ($i = 10; $i < $imgH; $i += 10) {
        imageline($image, 0, $i, $imgW, $i, $color_gray);
    }
    //»­ºáÏß
    for ($i = 10; $i < $imgW; $i += 10) {
        imageline($image, $i, 0, $i, $imgH, $color_gray);
    }
    //»­ÊúÏß
    imagepng($image);
    imagedestroy($image);
}
示例#2
0
function embroidery2image($embroidery, $scale_post = 1, $scale_pre = false)
{
    // Create image
    $im = imagecreatetruecolor(ceil($embroidery->imageWidth * $scale_post), ceil($embroidery->imageHeight * $scale_post));
    imagesavealpha($im, true);
    imagealphablending($im, false);
    $color = imagecolorallocatealpha($im, 255, 255, 255, 127);
    imagefill($im, 0, 0, $color);
    // Draw stitches
    foreach ($embroidery->blocks as $block) {
        $color = imagecolorallocate($im, $block->color->r, $block->color->g, $block->color->b);
        $x = false;
        foreach ($block->stitches as $stitch) {
            if ($x !== false) {
                imageline($im, ($x - $embroidery->min->x) * $scale_post, ($y - $embroidery->min->y) * $scale_post, ($stitch->x - $embroidery->min->x) * $scale_post, ($stitch->y - $embroidery->min->y) * $scale_post, $color);
            }
            $x = $stitch->x;
            $y = $stitch->y;
        }
    }
    // Scale finished image
    if ($scale_pre) {
        $im2 = imagecreatetruecolor($embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre);
        imagesavealpha($im2, true);
        imagealphablending($im2, false);
        imagecopyresized($im2, $im, 0, 0, 0, 0, $embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre, $embroidery->imageWidth * $scale_post, $embroidery->imageHeight * $scale_post);
        imagedestroy($im);
        $im = $im2;
    }
    return $im;
}
 function guvenlik_resmi()
 {
     $sifre = substr(md5(rand(0, 999999999999)), -5);
     if ($sifre) {
         $this->session->set_userdata('koruma', $sifre);
         $yukseklik = 62;
         $genislik = 200;
         $resim = ImageCreate($genislik, $yukseklik);
         $siyah = ImageColorAllocate($resim, 0, 0, 0);
         $kirmizi = ImageColorAllocate($resim, 182, 16, 99);
         $beyaz = ImageColorAllocate($resim, 255, 255, 255);
         ImageFill($resim, 0, 0, $beyaz);
         $font = 'css/comic.ttf';
         $font_boyut = 24;
         $sM = 30;
         $uM = 45;
         //kullanımı
         //resim adı, font boyutu, yazının açısı, yazının soldan margini, üstten margin, renk, font adı, şifrenin hangi digitinin yazılacağı bellirtiliyor
         imagettftext($resim, $font_boyut, rand(-45, 45), $sMa = $sM, $uM, rand(0, 255), $font, $sifre[0]);
         imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[1]);
         imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[2]);
         imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[3]);
         imagettftext($resim, $font_boyut, rand(-45, 45), $sM = $sMa + $sM, $uM, rand(0, 255), $font, $sifre[4]);
         //ImageRectangle($resim, 0, 0, $genislik-1, $yukseklik-1, $kirmizi);
         imageline($resim, 0, $yukseklik / 2, $genislik, $yukseklik / 2, $kirmizi);
         imageline($resim, $genislik / 2, 0, $genislik / 2, $yukseklik, $kirmizi);
         header("Content-Type: image/png");
         ImagePng($resim);
         ImageDestroy($resim);
     }
     exit;
 }
 public function index()
 {
     ob_clean();
     $image_handle = imagecreatetruecolor(150, 60);
     $white = imagecolorallocate($image_handle, 255, 255, 255);
     $rndm = imagecolorallocate($image_handle, rand(64, 192), rand(64, 192), rand(64, 192));
     imagefill($image_handle, 0, 0, $white);
     $fontName = PUBLICPATH . "/fonts/elephant.ttf";
     $myX = 15;
     $myY = 30;
     $angle = 0;
     for ($x = 0; $x <= 100; $x++) {
         $myX = rand(1, 148);
         $myY = rand(1, 58);
         imageline($image_handle, $myX, $myY, $myX + rand(-5, 5), $myY + rand(-5, 5), $rndm);
     }
     $myCryptBase = tep_create_random_value(50, 'digits');
     $secure_image_hash_string = "";
     for ($x = 0; $x <= 4; $x++) {
         $dark = imagecolorallocate($image_handle, rand(5, 128), rand(5, 128), rand(5, 128));
         $capChar = substr($myCryptBase, rand(1, 35), 1);
         $secure_image_hash_string .= $capChar;
         $fs = rand(20, 26);
         $myX = 15 + ($x * 28 + rand(-5, 5));
         $myY = rand($fs + 2, 55);
         $angle = rand(-30, 30);
         ImageTTFText($image_handle, $fs, $angle, $myX, $myY, $dark, $fontName, $capChar);
     }
     $this->session->set_userdata('secure_image_hash_string', $secure_image_hash_string);
     header("Content-type: image/jpeg");
     imagejpeg($image_handle, "", 95);
     imagedestroy($image_handle);
     die;
 }
示例#5
0
 function create($width = '120', $height = '40', $characters = '6')
 {
     ob_clean();
     $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;
     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);
     $this->Controller->Session->write('security_code', $code);
 }
示例#6
0
 public function index()
 {
     header("content-type:image/gif");
     $this->load->library('session');
     $width = 60;
     $height = 30;
     $img = imagecreatetruecolor($width, $height);
     $white = imagecolorallocate($img, 255, 255, 255);
     $color = imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255));
     $str = "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
     $code = "";
     for ($i = 0; $i < 5; $i++) {
         $code .= $str[rand(0, strlen($str) - 1)];
     }
     $this->session->set_userdata(array('myCode' => strtolower($code)));
     imagefilledrectangle($img, 0, 0, 60, 30, $color);
     for ($i = 0; $i < 100; $i++) {
         imagesetpixel($img, rand(0, 60), rand(0, 30), imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255)));
     }
     for ($i = 0; $i < 10; $i++) {
         imageline($img, rand(0, 60), rand(0, 30), rand(0, 60), rand(0, 30), imagecolorallocate($img, rand(0, 255), rand(0, 255), rand(0, 255)));
     }
     imagestring($img, 5, 10, 5, $code, $white);
     return imagegif($img);
     //imagedestroy($img);
 }
示例#7
0
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);
}
示例#8
0
 public function generate()
 {
     foreach ($this->__shapes as $shape) {
         $type = array_shift($shape);
         $color = array_shift($shape);
         $color = $this->_owner->imagecolorallocate(!isset($color) || is_null($color) ? $this->__base_color : $color, $this->__base_alpha);
         switch ($type) {
             case self::LINE:
                 imageline($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
                 break;
             case self::RECTANGLE:
                 imagerectangle($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
                 break;
             case self::FILLED_RECTANGLE:
                 imagefilledrectangle($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
                 break;
             case self::ELLIPSE:
                 imageellipse($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
                 break;
             case self::FILLED_ELLIPSE:
                 imagefilledellipse($this->_owner->image, $shape[0], $shape[1], $shape[2], $shape[3], $color);
                 break;
             case self::SPIRAL:
                 $angle = $r = 0;
                 while ($r <= $shape[2]) {
                     imagearc($this->_owner->image, $shape[0], $shape[1], $r, $r, $angle - $shape[3], $angle, $color);
                     $angle += $shape[3];
                     $r++;
                 }
                 break;
         }
     }
     return true;
 }
示例#9
0
 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);
 }
示例#10
0
 /**
  * Makes a graphical captcha from the provided text string
  *
  * @param string $captcha_text string to make image captcha from
  * @return string $data_url a data url containing the obfuscated image
  */
 function makeGraphicalCaptcha($captcha_text)
 {
     $image = @imagecreatetruecolor(195, 35);
     // defines background color, random lines color and text color
     $bg_color = imagecolorallocate($image, mt_rand(0, 255), 255, 0);
     imagefill($image, 0, 0, $bg_color);
     $lines_color = imagecolorallocate($image, 0x99, 0xcc, 0x99);
     $text_color = imagecolorallocate($image, mt_rand(0, 255), 0, 255);
     // draws random lines
     for ($i = 0; $i < 4; $i++) {
         imageline($image, 0, rand(0, 35), 195, rand(0, 35), $lines_color);
     }
     $captcha_letter_array = str_split($captcha_text);
     foreach ($captcha_letter_array as $i => $captcha_letter) {
         imagesetthickness($image, 1);
         imagestring($image, 5, 5 + $i * 35, rand(2, 14), $captcha_letter, $text_color);
     }
     // creates image
     ob_start();
     imagejpeg($image);
     $image_data = ob_get_contents();
     ob_end_clean();
     $data_url = "data:image/jpeg;base64," . base64_encode($image_data);
     imagedestroy($image);
     return $data_url;
 }
示例#11
0
 public function getVerify()
 {
     //创建画布
     $img = imagecreatetruecolor($this->config['width'], $this->config['height']);
     //设置背景颜色
     $bgColor = imagecolorallocate($img, 255, 255, 255);
     imagefill($img, 0, 0, $bgColor);
     $_x = ceil(($this->config['width'] - 20) / $this->config['lenght']);
     $code = '';
     //写入验证码
     for ($i = 0; $i < $this->config['lenght']; $i++) {
         $str = random();
         $code .= $str;
         $x = 10 + $i * $_x;
         $fontSize = mt_rand($this->config['fontsize'] - 10, $this->config['fontsize']);
         $fontH = imagefontheight($this->config['fontsize']);
         $y = mt_rand($fontH + 10, $this->config['height'] - 5);
         $fontColor = imagecolorallocate($img, mt_rand(0, 200), mt_rand(0, 200), mt_rand(0, 200));
         imagettftext($img, $fontSize, 0, $x, $y, $fontColor, $this->config['fontfile'], $str);
     }
     //增加干扰点
     for ($i = 0; $i < $this->config['point']; $i++) {
         $pointColor = imagecolorallocate($img, rand(150, 200), rand(150, 200), rand(100, 200));
         imagesetpixel($img, mt_rand(1, $this->config['width']), mt_rand(1, $this->config['height']), $pointColor);
     }
     //增加线干扰
     for ($i = 0; $i < $this->config['line']; $i++) {
         $linColor = imagecolorallocate($img, rand(0, 200), rand(0, 200), rand(0, 200));
         imageline($img, rand(0, $this->config['width']), rand(0, $this->config['height']), rand(0, $this->config['width']), rand(0, $this->config['height']), $linColor);
     }
     $_SESSION['Verify'] = md5(strtoupper($code));
     header('Content-type: image/png');
     imagepng($img);
     imagedestroy($img);
 }
示例#12
0
 public function setRandLine()
 {
     for ($i = 0; $i < $this->LineNumber; $i++) {
         $LineColor = imagecolorallocate($this->ImgObj, rand(0, 255), rand(0, 255), rand(0, 255));
         imageline($this->ImgObj, rand(0, $this->Width), rand(0, $this->Height), rand(0, $this->Width), rand(0, $this->Height), $LineColor);
     }
 }
示例#13
0
文件: Text.php 项目: rszabo/egalite
 /**
  * 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;
 }
示例#14
0
 public function generateCaptcha()
 {
     //make image
     $im = imagecreatetruecolor($this->width, $this->height);
     //set background
     $bg_color = imagecolorallocate($im, mt_rand($this->bg_color_min, $this->bg_color_max), mt_rand($this->bg_color_min, $this->bg_color_max), mt_rand($this->bg_color_min, $this->bg_color_max));
     //padding
     imagefill($im, 0, 0, $bg_color);
     //add lines
     for ($i = 0; $i < $this->lines; $i++) {
         //set color
         $line_color = imagecolorallocate($im, mt_rand($this->line_color_min, $this->line_color_max), mt_rand($this->line_color_min, $this->line_color_max), mt_rand($this->line_color_min, $this->line_color_max));
         //draw line
         imageline($im, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $line_color);
     }
     //add pixels
     for ($i = 0; $i < $this->pixels; $i++) {
         //set color
         $pixels_color = imagecolorallocate($im, mt_rand($this->pixels_color_min, $this->pixels_color_max), mt_rand($this->pixels_color_min, $this->pixels_color_max), mt_rand($this->pixels_color_min, $this->pixels_color_max));
         //draw pixels
         imagesetpixel($im, mt_rand(0, $this->width), mt_rand(0, $this->height), $pixels_color);
     }
     //get captcha string
     $captcha = $this->generateString();
     //set color of font
     $str_color = imagecolorallocate($im, mt_rand($this->font_color_min, $this->font_color_max), mt_rand($this->font_color_min, $this->font_color_max), mt_rand($this->font_color_min, $this->font_color_max));
     //put string to picture
     imagestring($im, $this->font, ceil($this->width / 2) - 20, ceil($this->height / 2) - 10, $captcha, $str_color);
     //save or output
     imagepng($im);
     //destroy res
     imagedestroy($im);
 }
示例#15
0
function verifyImage($type = 1, $length = 4, $pixel = 0, $line = 10, $sses_name = "verify")
{
    // 创建画布
    $width = 80;
    $height = 28;
    $image = imagecreatetruecolor($width, $height);
    $white = imagecolorallocate($image, 255, 255, 255);
    $balck = imagecolorallocate($image, 0, 0, 0);
    // 用填充矩形填充画布
    imagefilledrectangle($image, 1, 1, $width - 2, $height - 2, $white);
    $chars = buildRandomString($type, $length);
    $_SESSION[$sses_name] = $chars;
    for ($i = 0; $i < $length; $i++) {
        $size = mt_rand(14, 18);
        $angle = mt_rand(-15, 15);
        $x = 3 + $i * $size;
        $y = mt_rand(18, 22);
        $fontfile = "../fonts/" . "STFANGSO.TTF";
        $color = imagecolorallocate($image, mt_rand(50, 90), mt_rand(80, 200), mt_rand(90, 180));
        $text = substr($chars, $i, 1);
        imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $text);
    }
    // 加点
    for ($i = 0; $i < $pixel; $i++) {
        imagesetpixel($image, mt_rand(0, $width - 1), mt_rand(0, $height - 1), $balck);
    }
    // 加直线
    for ($i = 0; $i < $line; $i++) {
        $color = imagecolorallocate($image, mt_rand(50, 90), mt_rand(80, 200), mt_rand(90, 180));
        imageline($image, mt_rand(0, $width - 1), mt_rand(0, $height - 1), mt_rand(0, $width - 1), mt_rand(0, $height - 1), $color);
    }
    header("content-type:image/jpg");
    imagegif($image);
    imagedestroy($image);
}
示例#16
0
 /**
  * Create image from text (for captcha) 
  * @param int widht
  * @param int height	
  * @param string text
  * @param string Font (Arial)
  * @param int fontsize
  * @param string if not empty then save to file        
  * @param int randomline    
  */
 static function createImageTextKod($width, $height, $text, $TTFFile, $fontsize = 16, $file = '', $randomline = 2)
 {
     $img = imagecreate($width, $height);
     $col = imagecolorallocate($img, 255, 255, 255);
     $line = imagecolorallocate($img, 220, 220, 220);
     for ($i = 5; $i < $width; $i = $i + $fontsize) {
         imageline($img, $i, 0, $i, $height, $line);
     }
     for ($i = 5; $i < $height; $i = $i + $fontsize) {
         imageline($img, 0, $i, $width, $i, $line);
     }
     $c[0] = imagecolorallocate($img, 20, 50, 235);
     $c[1] = imagecolorallocate($img, 20, 220, 23);
     $c[2] = imagecolorallocate($img, 220, 20, 23);
     $c[3] = imagecolorallocate($img, 255, 120, 10);
     $c[4] = imagecolorallocate($img, 120, 120, 140);
     $c[5] = imagecolorallocate($img, 20, 130, 140);
     $c[6] = imagecolorallocate($img, 120, 130, 40);
     srand(time());
     for ($i = 0; $i < $randomline; $i++) {
         $color = $c[rand(0, 6)];
         $y1 = rand(0, $height);
         $y2 = rand(0, $height);
         imageline($img, 0, $y1, $width, $y2, $color);
     }
     for ($i = 0; $i < strlen($text); $i++) {
         $symb = substr($text, $i, 1);
         $color = $c[rand(0, 6)];
         $angle = rand(-15, 15);
         $y = $fontsize + intval($fontsize / 2) + intval($fontsize / 5) + rand(-intval($fontsize / 2), intval($fontsize / 2)) + 1;
         $x = $fontsize * $i + intval($fontsize / 2) + 1;
         imagettftext($img, $fontsize, $angle, $x, $y, $color, $TTFFile, $symb);
     }
     imagejpeg($img, $file, 90);
 }
 /**
  * Apply the effect to the image
  *
  * @param	object	$image
  * @access	public
  */
 function apply(&$image)
 {
     for ($i = 0, $rd = rand(0, 100), $gr = rand(0, 100), $bl = rand(0, 100); $i <= $image->height; $i++) {
         $g = @imagecolorallocate($image->handle, $rd += 2, $gr += 2, $bl += 2);
         @imageline($image->handle, 0, $i, $image->width, $i, $g);
     }
 }
示例#18
0
function drawLine()
{
    //header('Content-type: image/png');
    $png_image = imagecreate(150, 150);
    imagecolorallocate($png_image, 15, 142, 210);
    imagesetthickness($png_image, 5);
    $black = imagecolorallocate($png_image, 0, 0, 0);
    $x = 0;
    $y = 0;
    $w = imagesx($png_image) - 1;
    $z = imagesy($png_image) - 1;
    // Rectangle
    // imageline ($image, $x1, $y1, $x2, $y2, $color)
    imageline($png_image, $x, $y, $x, $y + $z, $black);
    imageline($png_image, $x, $y, $x + $w, $y, $black);
    imageline($png_image, $x + $w, $y, $x + $w, $y + $z, $black);
    imageline($png_image, $x, $y + $z, $x + $w, $y + $z, $black);
    // Lines
    imageline($png_image, $x, $y, $w, $z, $black);
    imagepng($png_image, 'simpletext.png');
    //imagepng($png_image);
    imagedestroy($png_image);
    $imgNumber = new NumberImage(1, 50, 50, 10);
    $imgNumber->setFileName("jedan");
    $imgNumber->drawNumberLineImage();
}
示例#19
0
 /**
  * 创建图像
  *
  * @return resource
  */
 protected function _createImage()
 {
     if (!is_resource($this->_image)) {
         extract($this->_options);
         //解出参数到变量
         $this->_image = imagecreatetruecolor($width, $height);
         $color1 = imagecolorallocate($this->_image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
         $color2 = imagecolorallocate($this->_image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
         $color1 = imagecolorsforindex($this->_image, $color1);
         $color2 = imagecolorsforindex($this->_image, $color2);
         $steps = $width;
         $r1 = ($color1['red'] - $color2['red']) / $steps;
         $g1 = ($color1['green'] - $color2['green']) / $steps;
         $b1 = ($color1['blue'] - $color2['blue']) / $steps;
         $x1 = 0;
         $y1 =& $i;
         $x2 = $width;
         $y2 =& $i;
         for ($i = 0; $i <= $steps; $i++) {
             $r2 = $color1['red'] - floor($i * $r1);
             $g2 = $color1['green'] - floor($i * $g1);
             $b2 = $color1['blue'] - floor($i * $b1);
             $color = imagecolorallocate($this->_image, $r2, $g2, $b2);
             imageline($this->_image, $x1, $y1, $x2, $y2, $color);
         }
         for ($i = 0, $count = mt_rand(10, 20); $i < $count; $i++) {
             $color = imagecolorallocatealpha($this->_image, mt_rand(20, 255), mt_rand(20, 255), mt_rand(100, 255), mt_rand(80, 120));
             imageline($this->_image, mt_rand(0, $width), 0, mt_rand(0, $width), $height, $color);
         }
     }
     return $this->_image;
 }
示例#20
0
function create_image()
{
    // *** Generate a passcode using md5
    //	(it will be all lowercase hex letters and numbers ***
    $md5 = md5(rand(0, 9999));
    $pass = substr($md5, 10, 5);
    // *** Set the session cookie so we know what the passcode is ***
    $_SESSION["pass"] = $pass;
    // *** Create the image resource ***
    $image = ImageCreatetruecolor(100, 20);
    // *** We are making two colors, white and black ***
    $clr_white = ImageColorAllocate($image, 255, 255, 255);
    $clr_black = ImageColorAllocate($image, 0, 0, 0);
    // *** Make the background black ***
    imagefill($image, 0, 0, $clr_black);
    // *** Set the image height and width ***
    imagefontheight(15);
    imagefontwidth(15);
    // *** Add the passcode in white to the image ***
    imagestring($image, 5, 30, 3, $pass, $clr_white);
    // *** Throw in some lines to trick those cheeky bots! ***
    imageline($image, 5, 1, 50, 20, $clr_white);
    imageline($image, 60, 1, 96, 20, $clr_white);
    // *** Return the newly created image in jpeg format ***
    return imagejpeg($image);
    // *** Just in case... ***
    imagedestroy($image);
}
示例#21
0
 /**
  * Class constructor generates the CAPTCHA image.
  *
  * @return blob the image
  * @access public
  */
 function __construct()
 {
     session_start();
     $image = imagecreate($this->width, $this->height);
     $random_str = $this->gen_str($this->chars_nr);
     #md5( microtime() );						// md5 to generate the random string
     $result_str = substr($random_str, 0, $this->chars_nr);
     //trim $chars_nr digit
     $bg_color = imagecolorallocate($image, $this->background_color['red'], $this->background_color['green'], $this->background_color['blue']);
     // background color
     $tx_color = imagecolorallocate($image, $this->text_color['red'], $this->text_color['gree'], $this->text_color['blue']);
     // text color
     for ($i = 0; $i <= $this->lines; $i++) {
         $line_color = imagecolorallocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
         //line color
         imageline($image, rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), rand(rand(-10, 100), rand(-10, 100)), $line_color);
         // Create lines on image
     }
     imagestring($image, 5, 20, 10, $result_str, $tx_color);
     // Draw a random string horizontally
     $_SESSION['key'] = $result_str;
     // Carry the data through session
     header("Content-type: image/png");
     // Out out the image
     imagepng($image);
     // Output image to browser
 }
 public function show()
 {
     $captchaText = strtoupper(substr(md5(microtime()), 0, 7));
     $this->Session->write('captcha', $captchaText);
     $image = imagecreate(190, 70);
     $background = imagecolorallocate($image, 255, 255, 255);
     $textColor = imagecolorallocatealpha($image, 0, 0, 0, 1);
     $x = 5;
     $y = 50;
     for ($i = 0; $i < 3000; $i++) {
         $fontSize = mt_rand(15, 28);
         $text = substr($captchaText, $i, 1);
         imagettftext($image, $fontSize, 0, $x, $y, $textColor, './impact.ttf', $text);
         $x = $x + 17 + mt_rand(0, 10);
         $y = mt_rand(40, 65);
         imagesetpixel($image, rand() % 235, rand() % 85, 3000000);
     }
     $line_color = imagecolorallocate($image, 4, rand() % 110, rand() % 220);
     for ($i = 0; $i < 10; $i++) {
         imageline($image, 0, rand() % 50, 200, rand() % 120, $line_color);
     }
     header("Content-type: application/jpeg");
     return imagejpeg($image);
     imagedestroy($image);
 }
示例#23
0
 static function codeimage()
 {
     $image = imagecreatetruecolor(100, 30);
     $bgcolor = imagecolorallocate($image, 255, 255, 255);
     imagefill($image, 0, 0, $bgcolor);
     $code = '';
     for ($i = 0; $i < 4; $i++) {
         $fontsize = 6;
         $fontcolor = imagecolorallocate($image, rand(0, 120), rand(0, 120), rand(0, 120));
         $data = "abcdefghjkmnpqrstuvwxy3456789";
         $fontcontent = substr($data, rand(1, strlen($data) - 1), 1);
         $code .= $fontcontent;
         $x = $i * 100 / 4 + rand(5, 10);
         $y = rand(5, 10);
         imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
     }
     for ($i = 0; $i < 200; $i++) {
         $pointcolor = imagecolorallocate($image, rand(50, 200), rand(50, 200), rand(50, 200));
         imagesetpixel($image, rand(1, 99), rand(1, 29), $pointcolor);
     }
     for ($i = 0; $i < 2; $i++) {
         $linecolor = imagecolorallocate($image, rand(80, 220), rand(80, 220), rand(80, 220));
         imageline($image, rand(1, 99), rand(1, 29), rand(1, 99), rand(1, 29), $linecolor);
     }
     $return['code'] = $code;
     $return['image'] = $image;
     return $return;
     //		header('content-type:image/png');
     //		imagepng($image);
 }
 function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6', $sec_code = '5')
 {
     $code = $sec_code;
     /* 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, 255, 255, 255);
     /* 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, './monofont.ttf', $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, './monofont.ttf', $code) or die('Error in imagettftext function');
     /* output captcha image to browser */
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
     //$this->mcode = $code;
 }
示例#25
0
 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);
 }
示例#26
0
function create_image()
{
    $image = imagecreatetruecolor(200, 50);
    $background_color = imagecolorallocate($image, 255, 255, 255);
    imagefilledrectangle($image, 0, 0, 200, 50, $background_color);
    $line_color = imagecolorallocate($image, 255, 0, 255);
    for ($i = 0; $i < 10; $i++) {
        imageline($image, 0, rand() % 50, 200, rand() % 25, $line_color);
    }
    $pixel_color = imagecolorallocate($image, 255, 0, 255);
    for ($i = 0; $i < 1000; $i++) {
        imagesetpixel($image, rand() % 200, rand() % 50, $pixel_color);
    }
    $letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    $len = strlen($letters);
    $letter = $letters[rand(0, $len - 1)];
    $text_color = imagecolorallocate($image, 0, 0, 0);
    $word = "";
    for ($i = 0; $i < 6; $i++) {
        $letter = $letters[rand(0, $len - 1)];
        imagestring($image, 5, 5 + $i * 30, 20, $letter, $text_color);
        $word .= $letter;
    }
    $_SESSION['security_key'] = $word;
    imagepng($image);
}
示例#27
0
 /**
  * Adds to the PNG image object, the data related to a row in the GIS dataset.
  *
  * @param string $spatial    GIS LINESTRING object
  * @param string $label      Label for the GIS LINESTRING object
  * @param string $line_color Color for the GIS LINESTRING object
  * @param array  $scale_data Array containing data related to scaling
  * @param image  $image      Image object
  *
  * @return the modified image object
  */
 public function prepareRowAsPng($spatial, $label, $line_color, $scale_data, $image)
 {
     // allocate colors
     $black = imagecolorallocate($image, 0, 0, 0);
     $red = hexdec(substr($line_color, 1, 2));
     $green = hexdec(substr($line_color, 3, 2));
     $blue = hexdec(substr($line_color, 4, 2));
     $color = imagecolorallocate($image, $red, $green, $blue);
     // Trim to remove leading 'LINESTRING(' and trailing ')'
     $linesrting = substr($spatial, 11, strlen($spatial) - 12);
     $points_arr = $this->extractPoints($linesrting, $scale_data);
     foreach ($points_arr as $point) {
         if (!isset($temp_point)) {
             $temp_point = $point;
         } else {
             // draw line section
             imageline($image, $temp_point[0], $temp_point[1], $point[0], $point[1], $color);
             $temp_point = $point;
         }
     }
     // print label if applicable
     if (isset($label) && trim($label) != '') {
         imagestring($image, 1, $points_arr[1][0], $points_arr[1][1], trim($label), $black);
     }
     return $image;
 }
示例#28
0
 public static function getCode($width = 70, $height = 24, $len = 4)
 {
     self::init();
     header('content-type:image/png');
     $checkWord = '';
     $checkChar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ1234567890';
     for ($num = 0; $num < $len; $num++) {
         $char = rand(0, strlen($checkChar) - 1);
         $checkWord .= $checkChar[$char];
     }
     $_SESSION['code'] = strtolower($checkWord);
     $image = imagecreate($width, $height);
     $font = FONTS_PATH . 'ariblk.ttf';
     $red = imagecolorallocate($image, 0xf3, 0x61, 0x61);
     $blue = imagecolorallocate($image, 0x53, 0x68, 0xbd);
     $green = imagecolorallocate($image, 0x6b, 0xc1, 0x46);
     $colors = array($red, $blue, $green);
     $gray = imagecolorallocate($image, 0xf5, 0xf5, 0xf5);
     imagefill($image, 0, 0, $gray);
     imageline($image, rand(0, 5), rand(6, 18), rand(65, 70), rand(6, 18), $colors[rand(0, 2)]);
     for ($num = 0; $num < $len; $num++) {
         imagettftext($image, rand(12, 16), (rand(0, 60) + 330) % 360, 5 + 15 * $num + rand(0, 4), 18 + rand(0, 4), $colors[rand(0, 2)], $font, $checkWord[$num]);
     }
     imagepng($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.85;
     $image = imagecreate($width, $height) or die(__('Cannot initialize new GD image stream', 'formbuilder'));
     /* 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', 'formbuilder'));
     $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', 'formbuilder'));
     /* output captcha image to browser */
     session_start();
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
     $_SESSION['security_code'] = $code;
 }
示例#30
0
function create_image()
{
    header("Content-Type: image/png");
    $image = imagecreatetruecolor(200, 50) or die("Cannot Initialize new GD image stream");
    $background_color = imagecolorallocate($image, 0, 0, 0);
    $text_color = imagecolorallocate($image, 122, 111, 255);
    $line_color = imagecolorallocate($image, 64, 64, 64);
    $pixel_color = imagecolorallocate($image, 0, 0, 255);
    imagefilledrectangle($image, 0, 0, 200, 50, $background_color);
    for ($i = 0; $i < 3; $i++) {
        imageline($image, 0, rand(0, 255) % 50, 200, rand(0, 255) % 50, $line_color);
    }
    for ($i = 0; $i < 1000; $i++) {
        imagesetpixel($image, rand() % 200, rand() % 50, $pixel_color);
    }
    $letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $len = strlen($letters);
    $letter = $letters[rand(0, $len - 1)];
    # $text_color = imagecolorallocate($image, 0, 0, 0);
    $word = "";
    for ($i = 0; $i < 6; $i++) {
        $letter = $letters[rand(0, $len - 1)];
        imagestring($image, 7, 5 + $i * 30, 20, $letter, $text_color);
        $word .= $letter;
    }
    $_SESSION['solution'] = $word;
    imagepng($image);
    imagedestroy($image);
}