Exemplo n.º 1
0
 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;
 }
 function createAICode()
 {
     global $bBlog;
     $code = $this->randomString();
     $bBlog->db->query("\n\tDELETE FROM `" . T_CHECKCODE . "` WHERE `timestamp`+3000<NOW()");
     $bBlog->db->query("\n\tINSERT INTO `" . T_CHECKCODE . "` ( `id` , `checksum` , `timestamp` )\n\tVALUES ('', '" . md5($code . $_SERVER["REMOTE_ADDR"]) . "', NOW( ))");
     if (!isset($plugins_dir)) {
         $plugins_dir = dirname(__FILE__) . '/';
     }
     $fontfile = "atomicclockradio.ttf";
     $font = $plugins_dir . $fontfile;
     $im = @imageCreate(110, 50) or die("Cannot Initialize new GD image stream");
     $background_color = imageColorAllocate($im, 195, 217, 255);
     $text_color = imageColorAllocate($im, 168, 18, 19);
     ImageTTFText($im, 20, 5, 18, 38, $text_color, $font, $code);
     // Date in the past
     header("Expires: Thu, 28 Aug 1997 05:00:00 GMT");
     // always modified
     $timestamp = gmdate("D, d M Y H:i:s");
     header("Last-Modified: " . $timestamp . " GMT");
     // HTTP/1.1
     header("Cache-Control: no-store, no-cache, must-revalidate");
     header("Cache-Control: post-check=0, pre-check=0", false);
     // HTTP/1.0
     header("Pragma: no-cache");
     // dump out the image
     header("Content-type: image/png");
     ImagePNG($im);
 }
 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;
 }
 function create_error($text)
 {
     $text = $text;
     $size = "8";
     $font = "classes/fonts/trebuchet.ttf";
     $TextBoxSize = imagettfbbox($size, 0, $font, preg_replace("/\\[br\\]/is", "\r\n", $text));
     $TxtBx_Lwr_L_x = $TextBoxSize[0];
     $TxtBx_Lwr_L_y = $TextBoxSize[1];
     $TxtBx_Lwr_R_x = $TextBoxSize[2];
     $TxtBx_Lwr_R_y = $TextBoxSize[3];
     $TxtBx_Upr_R_x = $TextBoxSize[4];
     $TxtBx_Upr_R_y = $TextBoxSize[5];
     $TxtBx_Upr_L_x = $TextBoxSize[6];
     $TxtBx_Upr_L_y = $TextBoxSize[7];
     $width = max($TxtBx_Lwr_R_x, $TxtBx_Upr_R_x) - min($TxtBx_Lwr_L_x, $TxtBx_Upr_L_x);
     $height = max($TxtBx_Lwr_L_y, $TxtBx_Lwr_R_y) - min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
     $x = -min($TxtBx_Upr_L_x, $TxtBx_Lwr_L_x);
     $y = -min($TxtBx_Upr_R_y, $TxtBx_Upr_L_y);
     $img = imagecreate($width + 2, $height + 1);
     // Only PHP-Version 4.3.2 or higher
     if (function_exists('imageantialias')) {
         imageantialias($img, FALSE);
     }
     $white = imagecolorallocate($img, 255, 255, 255);
     $black = imagecolorallocate($img, 0, 0, 0);
     imagecolortransparent($img, $white);
     ImageTTFText($img, $size, 0, $x, $y, $black, $font, preg_replace("/<br>/is", "\r\n", $text));
     header("Content-Type: image/png");
     ImagePNG($img);
     ImageDestroy($img);
     exit;
 }
Exemplo n.º 5
0
function TextToImage($text, $separate_line_after_chars = 40, $size = 24, $rotate = 0, $padding = 2, $transparent = true, $color = array('red' => 0, 'grn' => 0, 'blu' => 0), $bg_color = array('red' => 255, 'grn' => 255, 'blu' => 255))
{
    $amount_of_lines = ceil(strlen($text) / $separate_line_after_chars);
    $x = explode("\n", $text);
    $final = '';
    foreach ($x as $key => $value) {
        $returnes = '';
        do {
            $first_part = mb_substr($value, 0, $separate_line_after_chars, 'utf-8');
            $value = "\n" . mb_substr($value, $separate_line_after_chars, null, 'utf-8');
            $returnes .= $first_part;
        } while (mb_strlen($value, 'utf-8') > $separate_line_after_chars);
        $final .= $returnes . "\n";
    }
    $text = $final;
    $width = $height = $offset_x = $offset_y = 0;
    $font = $_SERVER['DOCUMENT_ROOT'] . '/assets/css/journal.ttf';
    // get the font height.
    $bounds = ImageTTFBBox($size, $rotate, $font, "W");
    if ($rotate < 0) {
        $font_height = abs($bounds[7] - $bounds[1]);
    } elseif ($rotate > 0) {
        $font_height = abs($bounds[1] - $bounds[7]);
    } else {
        $font_height = abs($bounds[7] - $bounds[1]);
    }
    // determine bounding box.
    $bounds = ImageTTFBBox($size, $rotate, $font, $text);
    if ($rotate < 0) {
        $width = abs($bounds[4] - $bounds[0]);
        $height = abs($bounds[3] - $bounds[7]);
        $offset_y = $font_height;
        $offset_x = 0;
    } elseif ($rotate > 0) {
        $width = abs($bounds[2] - $bounds[6]);
        $height = abs($bounds[1] - $bounds[5]);
        $offset_y = abs($bounds[7] - $bounds[5]) + $font_height;
        $offset_x = abs($bounds[0] - $bounds[6]);
    } else {
        $width = abs($bounds[4] - $bounds[6]);
        $height = abs($bounds[7] - $bounds[1]);
        $offset_y = $font_height;
        $offset_x = 0;
    }
    $image = imagecreate($width + $padding * 2 + 1, $height + $padding * 2 + 1);
    $background = ImageColorAllocate($image, $bg_color['red'], $bg_color['grn'], $bg_color['blu']);
    $foreground = ImageColorAllocate($image, $color['red'], $color['grn'], $color['blu']);
    if ($transparent) {
        ImageColorTransparent($image, $background);
    }
    ImageInterlace($image, true);
    // render the image
    ImageTTFText($image, $size, $rotate, $offset_x + $padding, $offset_y + $padding, $foreground, $font, $text);
    imagealphablending($image, true);
    imagesavealpha($image, true);
    // output PNG object.
    imagePNG($image, 'signature.png');
    imagedestroy($image);
}
 public function QrCode($assetId, $data, $display)
 {
     //split出display中的内容
     $displayArr = split('/', $display);
     $display = '编号:' . $displayArr[0] . PHP_EOL . '名称:' . $displayArr[1] . PHP_EOL . '型号:' . $displayArr[2];
     // 二维码数据
     // $data = 'helloworld';
     // 生成的文件名(路径)
     $codeTemp = 'qrCode/codeTemp.png';
     // 纠错级别:L、M、Q、H
     $errorCorrectionLevel = 'L';
     // 点的大小:1到10
     $matrixPointSize = 4;
     //创建一个二维码文件
     QRcode::png($data, $codeTemp, $errorCorrectionLevel, $matrixPointSize, 2);
     //输入二维码到浏览器
     //QRcode::png($data);
     //获取图片的宽高
     $size = getimagesize($codeTemp);
     $width = $size[0];
     $height = $size[1];
     //生成文本图片
     $textTemp = 'qrCode/textTemp.png';
     $im = imagecreate($width, 60);
     //图片的宽度高度
     $black = ImageColorAllocate($im, 255, 255, 2555);
     //背景颜色
     $white = ImageColorAllocate($im, 0, 0, 0);
     //字体颜色
     ImageTTFText($im, 10, 0, 10, 20, $white, "simhei.ttf", $display);
     imagepng($im, $textTemp);
     //图片拼接
     $bigphoto = $codeTemp;
     $footerphoto = $textTemp;
     $biginfo = getimagesize($bigphoto);
     $footerinfo = getimagesize($footerphoto);
     $bigwidth = $biginfo[0];
     $bigheight = $biginfo[1];
     $footerwidth = $footerinfo[0];
     $footerheight = $footerinfo[1];
     $initwidth = max(array($bigwidth, $footerwidth));
     $initheight = max(array($bigheight, $footerheight)) + min(array($bigheight, $footerheight));
     // header("Content-type: image/png");
     $im = imagecreatetruecolor($initwidth, $initheight);
     imagecopyresized($im, imagecreatefrompng($bigphoto), 0, 0, 0, 0, $bigwidth, $bigheight, $bigwidth, $bigheight);
     imagecopyresized($im, imagecreatefrompng($footerphoto), 0, $bigheight, 0, 0, $footerwidth, $footerheight, $footerwidth, $footerheight);
     $num = rand(0, 1000);
     // echo var_dump($num);
     $finalQRCode = "qrCode/finalQRCode" . $num . ".jpeg";
     // session_start();
     // $_SESSION["finalQRCode"]=$finalQRCode;
     imagepng($im, $finalQRCode);
     return $finalQRCode;
     // echo "<script language=\"JavaScript\">alert(\"添加成功\");</script>";
     // $this->render('add',array('type' => $type));
 }
Exemplo n.º 7
0
 /**
  * Generates Image file for captcha
  *
  * @param string $location
  * @param string $char_seq
  * @return unknown
  */
 function _generate_image($location, $char_seq)
 {
     $num_chars = strlen($char_seq);
     $img = imagecreatetruecolor($this->width, $this->height);
     imagealphablending($img, 1);
     imagecolortransparent($img);
     // generate background of randomly built ellipses
     for ($i = 1; $i <= 200; $i++) {
         $r = round(rand(0, 100));
         $g = round(rand(0, 100));
         $b = round(rand(0, 100));
         $color = imagecolorallocate($img, $r, $g, $b);
         imagefilledellipse($img, round(rand(0, $this->width)), round(rand(0, $this->height)), round(rand(0, $this->width / 16)), round(rand(0, $this->height / 4)), $color);
     }
     $start_x = round($this->width / $num_chars);
     $max_font_size = $start_x;
     $start_x = round(0.5 * $start_x);
     $max_x_ofs = round($max_font_size * 0.9);
     // set each letter with random angle, size and color
     for ($i = 0; $i <= $num_chars; $i++) {
         $r = round(rand(127, 255));
         $g = round(rand(127, 255));
         $b = round(rand(127, 255));
         $y_pos = $this->height / 2 + round(rand(5, 20));
         $fontsize = round(rand(18, $max_font_size));
         $color = imagecolorallocate($img, $r, $g, $b);
         $presign = round(rand(0, 1));
         $angle = round(rand(0, 25));
         if ($presign == true) {
             $angle = -1 * $angle;
         }
         $fontpath = dirname(__FILE__) . '/';
         ImageTTFText($img, $fontsize, $angle, $start_x + $i * $max_x_ofs, $y_pos, $color, $fontpath . 'default.ttf', substr($char_seq, $i, 1));
     }
     // create image file
     imagejpeg($img, $location, $this->jpg_quality);
     chmod($location, 0777);
     flush();
     imagedestroy($img);
     // clean up
     $tmp_dir = dir($this->temp_dir);
     while ($entry = $tmp_dir->read()) {
         if (strpos($entry, 'cap_') !== false) {
             $del_file = $this->temp_dir . '/' . $entry;
             if (is_file($del_file)) {
                 if (time() - filemtime($del_file) > 360) {
                     //5 min
                     unlink($del_file);
                 }
             }
         }
     }
     return true;
 }
Exemplo n.º 8
0
 function draw()
 {
     $width = 0;
     $height = 0;
     $offset_x = 0;
     $offset_y = 0;
     $bounds = array();
     $image = "";
     // get the font height.
     $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, "W");
     if ($this->rot < 0) {
         $font_height = abs($bounds[7] - $bounds[1]);
     } else {
         if ($this->rot > 0) {
             $font_height = abs($bounds[1] - $bounds[7]);
         } else {
             $font_height = abs($bounds[7] - $bounds[1]);
         }
     }
     // determine bounding box.
     $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, $this->msg);
     if ($this->rot < 0) {
         $width = abs($bounds[4] - $bounds[0]);
         $height = abs($bounds[3] - $bounds[7]);
         $offset_y = $font_height;
         $offset_x = 0;
     } else {
         if ($this->rot > 0) {
             $width = abs($bounds[2] - $bounds[6]);
             $height = abs($bounds[1] - $bounds[5]);
             $offset_y = abs($bounds[7] - $bounds[5]) + $font_height;
             $offset_x = abs($bounds[0] - $bounds[6]);
         } else {
             $width = abs($bounds[4] - $bounds[6]);
             $height = abs($bounds[7] - $bounds[1]);
             $offset_y = $font_height;
             $offset_x = 0;
         }
     }
     $image = imagecreate($width + $this->padX * 2 + 1, $height + $this->padY * 2 + 1);
     $background = ImageColorAllocate($image, $this->bg_red, $this->bg_grn, $this->bg_blu);
     $foreground = ImageColorAllocate($image, $this->red, $this->grn, $this->blu);
     if ($this->transparent) {
         ImageColorTransparent($image, $background);
     }
     ImageInterlace($image, false);
     // render the image
     ImageTTFText($image, $this->size, $this->rot, $offset_x + $this->padX, $offset_y + $this->padY, $foreground, $this->font, $this->msg);
     // output PNG object.
     imagePNG($image);
 }
Exemplo n.º 9
0
 public function setimg($img, $age, $gender, $score, $infos, $res, $skin, $huitou, $target, $types)
 {
     $dst = "/mnt/meilimei/m/upload/mojokbg.png";
     //得到原始图片信息
     $dst_im = imagecreatefrompng($dst);
     $dst_info = getimagesize($dst);
     //水印图像
     $src = "/mnt/meilimei/m/upload/mojokbg2.png";
     $src_im = imagecreatefrompng($src);
     $src_info = getimagesize($src);
     if ($types == 'image/png') {
         $im = imagecreatefrompng($img);
         //imagecreatefrompng
     } elseif ($types == 'image/jpeg') {
         $im = imagecreatefromjpeg($img);
     } elseif ($types == 'image/gif') {
         $im = imagecreatefromgif($img);
     } elseif ($types == 'image/bmp') {
         $im = imagecreatefromwbmp($img);
     }
     $im_src = getimagesize($img);
     $temp_img = imagecreatetruecolor(320, 480);
     //创建画布
     //$im=create($src);
     imagecopyresampled($temp_img, $im, 0, 0, 0, 0, 226, 313, $im_src[0], $im_src[1]);
     //人脸
     $alpha = 100;
     imagecopy($dst_im, $temp_img, 48, 75, 0, 0, 226, 313);
     //后人脸
     imagecopy($dst_im, $src_im, 45, 72, 0, 0, 237, 323);
     //背景
     //$im = imagecreate(400 , 300);
     $gray = ImageColorAllocate($dst_im, 255, 255, 255);
     $pink = ImageColorAllocate($dst_im, 246, 109, 152);
     $fontfilebold = "/mnt/meilimei/m/upload/msyhbd.ttf";
     $fontfile = "/mnt/meilimei/m/upload/msyh.ttf";
     $str = iconv('GB2312', 'UTF-8', $huitou . '%');
     $str1 = $infos;
     $str2 = iconv('GB2312', 'UTF-8', $skin);
     $str3 = iconv('GB2312', 'UTF-8', $score);
     $str4 = iconv('GB2312', 'UTF-8', $age);
     ImageTTFText($dst_im, 22, 0, 175, 40, $gray, $fontfilebold, $str);
     ImageTTFText($dst_im, 11, 0, 50, 65, $gray, $fontfile, $str1);
     ImageTTFText($dst_im, 19, 0, 67, 225, $pink, $fontfilebold, $str2);
     ImageTTFText($dst_im, 19, 0, 67, 273, $pink, $fontfilebold, $str3);
     ImageTTFText($dst_im, 19, 0, 67, 320, $pink, $fontfilebold, $str4);
     imagesavealpha($src_im, true);
     imagesavealpha($dst_im, true);
     Imagepng($dst_im, "/mnt/meilimei/m/upload/webmojing/" . date('Y') . '/' . date('m') . '/' . $target . ".jpg");
     return ImageDestroy($dst_im);
 }
Exemplo n.º 10
0
 function showImage()
 {
     $noise = true;
     $nb_noise = 10;
     $image = imagecreatetruecolor($this->height, $this->width);
     $width = imagesx($image);
     $height = imagesy($image);
     $back = ImageColorAllocate($image, intval(rand(224, 255)), intval(rand(224, 255)), intval(rand(224, 255)));
     ImageFilledRectangle($image, 0, 0, $width, $height, $back);
     if ($noise) {
         for ($i = 0; $i < $nb_noise; $i++) {
             $size = intval(rand(6, 14));
             $angle = intval(rand(0, 360));
             $x = intval(rand(10, $width - 10));
             $y = intval(rand(0, $height - 5));
             $color = imagecolorallocate($image, intval(rand(160, 224)), intval(rand(160, 224)), intval(rand(160, 224)));
             $text = chr(intval(rand(45, 250)));
             ImageTTFText($image, $size, $angle, $x, $y, $color, $this->get_font(), $this->code);
         }
         //$i = 0; $i < $nb_noise; $i++
     } else {
         for ($i = 0; $i < $width; $i += 10) {
             $color = imagecolorallocate($image, intval(rand(160, 224)), intval(rand(160, 224)), intval(rand(160, 224)));
             imageline($image, $i, 0, $i, $height, $color);
         }
         //$i = 0; $i < $width; $i += 10
         for ($i = 0; $i < $height; $i += 10) {
             $color = imagecolorallocate($image, intval(rand(160, 224)), intval(rand(160, 224)), intval(rand(160, 224)));
             imageline($image, 0, $i, $width, $i, $color);
         }
         //$i = 0; $i < $height; $i += 10
     }
     for ($i = 0, $x = 5; $i < strlen($this->code); $i++) {
         $r = intval(rand(0, 128));
         $g = intval(rand(0, 128));
         $b = intval(rand(0, 128));
         $color = ImageColorAllocate($image, $r, $g, $b);
         $shadow = ImageColorAllocate($image, $r + 128, $g + 128, $b + 128);
         $size = intval(rand(14, 19));
         $angle = intval(rand(-20, 20));
         $text = strtoupper(substr($this->code, $i, 1));
         ImageTTFText($image, $size, $angle, $x + 7, 26, $shadow, $this->get_font(), $text);
         ImageTTFText($image, $size - 1, $angle + 2, $x + 5, 24, $color, $this->get_font(), $text);
         $x += $size + 2;
     }
     //$i = 0, $x = 5; $i < strlen($this->code); $i++
     header('Content-type: image/jpeg');
     imagejpeg($image);
     ImageDestroy($image);
 }
Exemplo n.º 11
0
function writeImage($width, $height, $strLen, $fontSize, $angMax, $font, $penColorRGB, $backColorRGB)
{
    $im = Imagecreate($width, $height);
    $backColorArray = explode(',', $backColorRGB);
    // Get RGB componenets
    // from string
    $penColorArray = explode(',', $penColorRGB);
    $backColor = imagecolorallocate($im, $backColorArray[0], $backColorArray[1], $backColorArray[2]);
    // allocate
    // color
    // for
    // background
    $penColor = imagecolorallocate($im, $penColorArray[0], $penColorArray[1], $penColorArray[2]);
    // allocate
    // color
    // for
    // writing
    $x = 20;
    // Start writing from $x with initial 20 pixels left blank
    $y = $fontSize + 20;
    $str = "";
    // Declaration just to avoid "undefined variable" warning
    for ($i = 0; $i <= $strLen - 1; $i++) {
        $chr = getRandChr();
        // Generate a random character
        $str .= "{$chr}";
        // Append to a string, for storing to SESSION
        $angle = rand(0, $angMax);
        // Set angle between 0 to $angMax
        if (rand(0, 1) == 0) {
            // Set Positive or Negative angle randomly
            $angle = -$angle;
        }
        ImageTTFText($im, $fontSize, $angle, $x, $y, $penColor, $font, $chr);
        $x = $x + 50;
        // Increment in x coordinate
    }
    $_SESSION['CaptchaCode'] = md5($str);
    // Assuming session is already
    // started, final CAPTCHA string
    // is stored in session
    header('Content-type: image/jpeg');
    // Set header
    imagejpeg($im);
    // produce jpeg image
    imagedestroy($im);
    // free-up temporary memory used to store image
}
Exemplo n.º 12
0
 /**
  * Create a simple sume captcha
  */
 public function sumeCaptcha()
 {
     $val1 = rand(1, 9);
     $val2 = rand(1, 9);
     $result = $val1 + $vale;
     $txtCode = $val1 . ' + ' . $val2;
     $img = ImageCreateFromGIF('img/captcha/bg.gif');
     $bg = ImageColorAllocate($img, 240, 240, 240);
     $color = ImageColorAllocate($img, 0, 0, 0);
     $font = 'img/others/arial.ttf';
     // Create the Captcha image
     ImageTTFText($img, 20, 0, 13, 30, $color, $font, $txtCode);
     ImageJPEG($img, 'img/captcha/box.jpg', 75);
     ImageDestroy($img);
     return $result;
 }
Exemplo n.º 13
0
 public function draw()
 {
     $font = $this->_getFont();
     $htexte = 'dg' . $this->getText();
     $hdim = ImageTTFBBox($this->getSize(), 0, $font, $htexte);
     $wdim = ImageTTFBBox($this->getSize(), 0, $font, $this->getText());
     $dx = max($wdim[2], $wdim[4]) - min($wdim[0], $wdim[6]) + ceil($this->getSize() / 8);
     $dy = max($hdim[1], $hdim[3]) - min($hdim[5], $hdim[7]) + ceil($this->getSize() / 8);
     $img = ImageCreate(max($dx, 1), max($dy, 1));
     $noir = ImageColorAllocate($img, 0, 0, 0);
     $blanc = ImageColorAllocate($img, 255, 255, 255);
     $blanc = imagecolortransparent($img, $blanc);
     ImageFilledRectangle($img, 0, 0, $dx, $dy, $blanc);
     ImageTTFText($img, $this->getSize(), $angle, 0, -min($hdim[5], $hdim[7]), $noir, $font, $this->getText());
     return $img;
 }
Exemplo n.º 14
0
 function make_captcha($noise = true, $private_key, $fpath)
 {
     $font_file = JPATH_ROOT . DS . 'components' . DS . 'com_socialnetworking' . DS . 'assets' . DS . 'Dustismo.ttf';
     $image = imagecreatetruecolor(120, 30);
     $back = ImageColorAllocate($image, intval(rand(224, 255)), intval(rand(224, 255)), intval(rand(224, 255)));
     ImageFilledRectangle($image, 0, 0, 120, 30, $back);
     if ($noise) {
         // rand characters in background with random position, angle, color
         for ($i = 0; $i < 30; $i++) {
             $size = intval(rand(6, 14));
             $angle = intval(rand(0, 360));
             $x = intval(rand(10, 120 - 10));
             $y = intval(rand(0, 30 - 5));
             $color = imagecolorallocate($image, intval(rand(160, 224)), intval(rand(160, 224)), intval(rand(160, 224)));
             $text = chr(intval(rand(45, 250)));
             ImageTTFText($image, $size, $angle, $x, $y, $color, $font_file, $text);
         }
     } else {
         // random grid color
         for ($i = 0; $i < 120; $i += 10) {
             $color = imagecolorallocate($image, intval(rand(160, 224)), intval(rand(160, 224)), intval(rand(160, 224)));
             imageline($image, $i, 0, $i, 30, $color);
         }
         for ($i = 0; $i < 30; $i += 10) {
             $color = imagecolorallocate($image, intval(rand(160, 224)), intval(rand(160, 224)), intval(rand(160, 224)));
             imageline($image, 0, $i, 120, $i, $color);
         }
     }
     // private text to read
     for ($i = 0, $x = 5; $i < 6; $i++) {
         $r = intval(rand(0, 128));
         $g = intval(rand(0, 128));
         $b = intval(rand(0, 128));
         $color = ImageColorAllocate($image, $r, $g, $b);
         $shadow = ImageColorAllocate($image, $r + 128, $g + 128, $b + 128);
         $size = intval(rand(12, 17));
         $angle = intval(rand(-30, 30));
         $text = strtoupper(substr($private_key, $i, 1));
         ImageTTFText($image, $size, $angle, $x + 2, 26, $shadow, $font_file, $text);
         ImageTTFText($image, $size, $angle, $x, 24, $color, $font_file, $text);
         $x += $size + 2;
     }
     imagepng($image, $fpath);
     ImageDestroy($image);
 }
Exemplo n.º 15
0
 function process()
 {
     global $CONFIG;
     $matches = array();
     if (!preg_match("/^([0-9a-zA-Z]+)\\.png\$/", $this->file, $matches)) {
         error_exit("Invalid image request for {$this->file}");
     }
     $code = $matches[1];
     $basepath = trim($CONFIG['paths']['base_url'], '/') . '/image/pins';
     $basefile = trim($CONFIG['paths']['file_path'], '/') . '/image/pins';
     $localfile = "{$basefile}/{$code}.png";
     if (file_exists($localfile)) {
         header("Location: http://{$_SERVER['HTTP_HOST']}/{$basepath}/{$code}.png");
     } else {
         if (!function_exists('ImageCreateFromPNG')) {
             header("Location: http://{$_SERVER['HTTP_HOST']}/{$basepath}/blank-marker.png");
         } else {
             $font = 'ttf-bitstream-vera/Vera';
             $size = 6;
             if (strlen($code) < 3) {
                 # Bigger image for number-only pins
                 $size = 8;
             }
             $im = ImageCreateFromPNG("{$basefile}/blank-marker.png");
             imageSaveAlpha($im, true);
             $tsize = ImageTTFBBox($size, 0, $font, $code);
             $textbg = ImageColorAllocate($im, 255, 119, 207);
             $black = ImageColorAllocate($im, 0, 0, 0);
             $dx = abs($tsize[2] - $tsize[0]);
             $dy = abs($tsize[5] - $tsize[3]);
             $x = (ImageSx($im) - $dx) / 2 + 1;
             $y = (ImageSy($im) - $dy) / 2;
             ImageTTFText($im, $size, 0, $x, $y, $black, $font, $code);
             header('Content-Type: image/png');
             ImagePNG($im);
             ImagePNG($im, $localfile);
             ImageDestroy($im);
         }
     }
     exit;
 }
Exemplo n.º 16
0
function create_image($text, $size, $font, $color, $bgcolor, $x = 0, $y = 0)
{
    if ($x > 0) {
        $img_x = $x;
    } else {
        $img_x = $size * 0.8 * strlen($text);
    }
    // the factor reduces the amount of whitespace at the end of the string
    if ($y > 0) {
        $img_y = $y;
    } else {
        $img_y = $size + 10;
    }
    $img_base = (int) (($size + 10) * 0.75);
    // a rough guesstimate of where the text baseline should be in the image
    // echo "Text is $text, $img_x, $img_y, $img_base, R: $r G: $g B: $b <br />"; exit;
    $im = @imageCreate($img_x, $img_y) or die("Cannot Initialize new GD image stream");
    $background_color = imageColorAllocate($im, hexdec(substr($bgcolor, 0, 2)), hexdec(substr($bgcolor, 2, 2)), hexdec(substr($bgcolor, 4, 2)));
    $text_color = imageColorAllocate($im, hexdec(substr($color, 0, 2)), hexdec(substr($color, 2, 2)), hexdec(substr($color, 4, 2)));
    ImageTTFText($im, $size, 0, 2, $img_base, $text_color, $font, $text);
    /*
    	// Date in the past
    	header("Expires: Thu, 28 Aug 1997 05:00:00 GMT");
    
    	// always modified
    	$timestamp = gmdate("D, d M Y H:i:s");
    	header("Last-Modified: " . $timestamp . " GMT");
     
    	// HTTP/1.1
    	header("Cache-Control: no-store, no-cache, must-revalidate");
    	header("Cache-Control: post-check=0, pre-check=0", false);
    
    	// HTTP/1.0
    	header("Pragma: no-cache");
    */
    // dump out the image
    header("Content-type: image/jpeg");
    ImageJPEG($im);
}
Exemplo n.º 17
0
 function BuildMessage()
 {
     $imgOutput = imagecreatefrompng(ABS_SYS_IFW . "injader.png");
     $intImageX = (imagesx($imgOutput) - strlen($this->strMessage)) / 5;
     // 20
     $intImageY = imagesy($imgOutput) - imagesy($imgOutput) / 3;
     // 65
     $imgTextColour = imagecolorallocate($imgOutput, 0, 0, 0);
     ImageTTFText($imgOutput, 25, -5, $intImageX, $intImageY, $imgTextColour, ABS_SYS_IFW . "FoundationRegular.ttf", $this->strMessage);
     header("Content-Type: image/png");
     header("Pragma: public");
     // required
     header("Expires: 0");
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     header("Cache-Control: private", false);
     // required for certain browsers
     header("Content-Transfer-Encoding: binary");
     header("Content-Disposition: attachment; filename=disp.png");
     imagepng($imgOutput);
     readfile($imgOutput);
     imagedestroy($imgOutput);
     exit;
 }
Exemplo n.º 18
0
 public function captcha_make()
 {
     $imgname = "captcha/src.gif";
     $im = ImageCreateFromGIF($imgname);
     //$im = @ImageCreate (100, 50) or die ("Cannot Initialize new GD image stream");
     $filename = "captcha/src/capt.gif";
     $background_color = ImageColorAllocate($im, 255, 255, 255);
     $text_color = ImageColorAllocate($im, 0, 0, 0);
     $string = "";
     $symbols = array("A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "2", "3", "4", "5", "6", "7", "8", "9");
     for ($i = 0; $i < 5; $i++) {
         $string .= $symbols[rand(0, sizeof($symbols) - 1)];
     }
     ImageTTFText($im, 24, 8, 5, 50, $text_color, "captcha/20527.ttf", $string);
     $this->session->set_userdata('cpt', md5(strtolower($string)));
     ImageGIF($im, $filename);
     return $filename;
     //return "zz";
     /*
     $imgname="captcha/src.gif";
     $im = @ImageCreateFromGIF($imgname);
     //$im = @ImageCreate (100, 50) or die ("Cannot Initialize new GD image stream");
     $filename="captcha/cp_".date("dmyHIS").rand(0,99).rand(0,99).".gif";
     $background_color = ImageColorAllocate($im, 255, 255, 255);
     $text_color = ImageColorAllocate($im, 0,0,0);
     $string="";
     $symbols=Array("A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z","2","3","4","5","6","7","8","9");
     for($i=0;$i<5;$i++){
     	$string.=$symbols[rand(0,(sizeof($symbols)-1))];
     }
     ImageTTFText ($im, 24, 8, 5, 50, $text_color, "captcha/20527.ttf",$string);
     $this->session->set_userdata('cpt', md5(strtolower($string)));
     ImageGIF ($im, $filename);
     return $filename;
     //return "zz";
     */
 }
Exemplo n.º 19
0
function imageAuthCode($width, $height)
{
    mt_srand((double) microtime() * 1000000);
    $auth_code = mt_rand(1000, 99999);
    $auth_code = md5($auth_code);
    $auth_code = substr($auth_code, 0, 5);
    $auth_code = strtoupper($auth_code);
    setcookie('image_auth_code', md5($auth_code), time() + 60 * 60, '/');
    $image = imagecreate($width, $height) or die("Can't initialize GD image stream");
    $bg_color = imagecolorallocate($image, 240, 248, 255);
    $line_color = imagecolorallocate($image, 150, 150, 150);
    $elpise_color = imagecolorallocate($image, 200, 200, 200);
    $text_color = imagecolorallocate($image, 0, 0, 0);
    $rand1_h = mt_rand(1, $height);
    $rand2_h = mt_rand(1, $height);
    $rand3_h = mt_rand(1, $height);
    $rand4_h = mt_rand(1, $height);
    $rand1_v = mt_rand(1, $width);
    $rand2_v = mt_rand(1, $width);
    $rand3_v = mt_rand(1, $width);
    $rand4_v = mt_rand(1, $width);
    imageline($image, 0, $rand1_h, 100, $rand1_h, $line_color);
    imageline($image, 0, $rand2_h, 100, $rand2_h, $line_color);
    imageline($image, 0, $rand3_h, 100, $rand3_h, $line_color);
    imageline($image, 0, $rand4_h, 100, $rand4_h, $line_color);
    imageline($image, $rand1_v, 0, $rand1_v, 50, $line_color);
    imageline($image, $rand2_v, 0, $rand2_v, 50, $line_color);
    imageline($image, $rand3_v, 0, $rand3_v, 50, $line_color);
    imageline($image, $rand4_v, 0, $rand4_v, 50, $line_color);
    imagefilledellipse($image, mt_rand(0, 100), mt_rand(0, 40), mt_rand(10, 40), mt_rand(10, 25), $elpise_color);
    imagefilledellipse($image, mt_rand(0, 100), mt_rand(0, 40), mt_rand(20, 40), mt_rand(10, 25), $elpise_color);
    ImageTTFText($image, 22, 0, 10, 20, $text_color, realpath('../ext_inc/fonts/captcha.ttf'), $auth_code);
    header("Content-type: image/png");
    imagepng($image);
    imagedestroy($image);
}
Exemplo n.º 20
0
 function _StrokeTTF($x, $y, $txt, $dir = 0, $paragraph_align = "left", $debug = false)
 {
     // Setupo default inter line margin for paragraphs to
     // 25% of the font height.
     $ConstLineSpacing = 0.25;
     // Remember the anchor point before adjustment
     if ($debug) {
         $ox = $x;
         $oy = $y;
     }
     if (!ereg("\n", $txt) || $dir > 0 && ereg("\n", $txt)) {
         // Format a single line
         $txt = $this->AddTxtCR($txt);
         $bbox = $this->GetBBoxTTF($txt, $dir);
         // Align x,y ot lower left corner of bbox
         $x -= $bbox[0];
         $y -= $bbox[1];
         // Note to self: "topanchor" is deprecated after we changed the
         // bopunding box stuff.
         if ($this->text_halign == "right" || $this->text_halign == "topanchor") {
             $x -= $bbox[2] - $bbox[0];
         } elseif ($this->text_halign == "center") {
             $x -= ($bbox[2] - $bbox[0]) / 2;
         }
         if ($this->text_valign == "top") {
             $y += abs($bbox[5]) + $bbox[1];
         } elseif ($this->text_valign == "center") {
             $y -= ($bbox[5] - $bbox[1]) / 2;
         }
         ImageTTFText($this->img, $this->font_size, $dir, $x, $y, $this->current_color, $this->font_file, $txt);
         if ($debug) {
             // Draw the bounding rectangle and the bounding box
             $box = @ImageTTFBBox($this->font_size, $dir, $this->font_file, $txt);
             $p = array();
             $p1 = array();
             for ($i = 0; $i < 4; ++$i) {
                 $p[] = $bbox[$i * 2] + $x;
                 $p[] = $bbox[$i * 2 + 1] + $y;
                 $p1[] = $box[$i * 2] + $x;
                 $p1[] = $box[$i * 2 + 1] + $y;
             }
             // Draw bounding box
             $this->PushColor('green');
             $this->Polygon($p1, true);
             $this->PopColor();
             // Draw bounding rectangle
             $this->PushColor('darkgreen');
             $this->Polygon($p, true);
             $this->PopColor();
             // Draw a cross at the anchor point
             $this->PushColor('red');
             $this->Line($ox - 15, $oy, $ox + 15, $oy);
             $this->Line($ox, $oy - 15, $ox, $oy + 15);
             $this->PopColor();
         }
     } else {
         // Format a text paragraph
         $fh = $this->GetFontHeight();
         // Line margin is 25% of font height
         $linemargin = round($fh * $ConstLineSpacing);
         $fh += $linemargin;
         $w = $this->GetTextWidth($txt);
         $y -= $linemargin / 2;
         $tmp = split("\n", $txt);
         $nl = count($tmp);
         $h = $nl * $fh;
         if ($this->text_halign == "right") {
             $x -= $dir == 0 ? $w : $h;
         } elseif ($this->text_halign == "center") {
             $x -= $dir == 0 ? $w / 2 : $h / 2;
         }
         if ($this->text_valign == "top") {
             $y += $dir == 0 ? $h : $w;
         } elseif ($this->text_valign == "center") {
             $y += $dir == 0 ? $h / 2 : $w / 2;
         }
         // Here comes a tricky bit.
         // Since we have to give the position for the string at the
         // baseline this means thaht text will move slightly up
         // and down depending on any of it's character descend below
         // the baseline, for example a 'g'. To adjust the Y-position
         // we therefore adjust the text with the baseline Y-offset
         // as used for the current font and size. This will keep the
         // baseline at a fixed positoned disregarding the actual
         // characters in the string.
         $standardbox = $this->GetTTFBBox('Gg', $dir);
         $yadj = $standardbox[1];
         $xadj = $standardbox[0];
         for ($i = 0; $i < $nl; ++$i) {
             $wl = $this->GetTextWidth($tmp[$i]);
             $bbox = $this->GetTTFBBox($tmp[$i], $dir);
             if ($paragraph_align == "left") {
                 $xl = $x;
             } elseif ($paragraph_align == "right") {
                 $xl = $x + ($w - $wl);
             } else {
                 // Center
                 $xl = $x + $w / 2 - $wl / 2;
             }
             $xl -= $bbox[0];
             $yl = $y - $yadj;
             $xl = $xl - $xadj;
             ImageTTFText($this->img, $this->font_size, $dir, $xl, $yl - ($h - $fh) + $fh * $i, $this->current_color, $this->font_file, $tmp[$i]);
             if ($debug) {
                 // Draw the bounding rectangle around each line
                 $box = @ImageTTFBBox($this->font_size, $dir, $this->font_file, $tmp[$i]);
                 $p = array();
                 for ($j = 0; $j < 4; ++$j) {
                     $p[] = $bbox[$j * 2] + $xl;
                     $p[] = $bbox[$j * 2 + 1] + $yl - ($h - $fh) + $fh * $i;
                 }
                 // Draw bounding rectangle
                 $this->PushColor('darkgreen');
                 $this->Polygon($p, true);
                 $this->PopColor();
             }
         }
         if ($debug) {
             // Draw a cross at the anchor point
             $this->PushColor('red');
             $this->Line($ox - 25, $oy, $ox + 25, $oy);
             $this->Line($ox, $oy - 25, $ox, $oy + 25);
             $this->PopColor();
         }
     }
 }
Exemplo n.º 21
0
 function DrawText($which_font, $which_angle, $which_xpos, $which_ypos, $which_color, $which_text, $which_halign = 'left', $which_valign = 'bottom')
 {
     // TTF:
     if ($this->use_ttf) {
         $size = $this->TTFBBoxSize($which_font['size'], $which_angle, $which_font['font'], $which_text);
         $rads = deg2rad($which_angle);
         if ($which_valign == 'center') {
             $which_ypos += $size[1] / 2;
         } elseif ($which_valign == 'bottom') {
             $which_ypos += $size[1];
         }
         if ($which_halign == 'center') {
             $which_xpos -= $size[0] / 2 * cos($rads);
         } elseif ($which_halign == 'left') {
             $which_xpos += $size[0] * sin($rads);
         } elseif ($which_halign == 'right') {
             $which_xpos -= $size[0] * cos($rads);
         }
         ImageTTFText($this->img, $which_font['size'], $which_angle, $which_xpos, $which_ypos, $which_color, $which_font['font'], $which_text);
     } else {
         // Split the text by its lines, and count them
         $which_text = ereg_replace("\r", "", $which_text);
         $str = split("\n", $which_text);
         $nlines = count($str);
         $spacing = $this->line_spacing * ($nlines - 1);
         // Vertical text:
         // (Remember the alignment convention with vertical text)
         if ($which_angle == 90) {
             // The text goes around $which_xpos.
             if ($which_halign == 'center') {
                 $which_xpos -= $nlines * ($which_font['height'] + $spacing) / 2;
             } elseif ($which_halign == 'right') {
                 $which_xpos -= $nlines * ($which_font['height'] + $spacing);
             }
             $ypos = $which_ypos;
             for ($i = 0; $i < $nlines; $i++) {
                 // Center the text vertically around $which_ypos (each line)
                 if ($which_valign == 'center') {
                     $ypos = $which_ypos + strlen($str[$i]) * $which_font['width'] / 2;
                 }
                 // Make the text finish (vertically) at $which_ypos
                 if ($which_valign == 'bottom') {
                     $ypos = $which_ypos + strlen($str[$i]) * $which_font['width'];
                 }
                 ImageStringUp($this->img, $which_font['font'], $i * ($which_font['height'] + $spacing) + $which_xpos, $ypos, $str[$i], $which_color);
             }
         } else {
             // The text goes above $which_ypos
             if ($which_valign == 'top') {
                 $which_ypos -= $nlines * ($which_font['height'] + $spacing);
             }
             // The text is centered around $which_ypos
             if ($which_valign == 'center') {
                 $which_ypos -= $nlines * ($which_font['height'] + $spacing) / 2;
             }
             // valign = 'bottom' requires no modification
             $xpos = $which_xpos;
             for ($i = 0; $i < $nlines; $i++) {
                 // center the text around $which_xpos
                 if ($which_halign == 'center') {
                     $xpos = $which_xpos - strlen($str[$i]) * $which_font['width'] / 2;
                 }
                 // make the text finish at $which_xpos
                 if ($which_halign == 'right') {
                     $xpos = $which_xpos - strlen($str[$i]) * $which_font['width'];
                 }
                 ImageString($this->img, $which_font['font'], $xpos, $i * ($which_font['height'] + $spacing) + $which_ypos, $str[$i], $which_color);
             }
         }
     }
     return TRUE;
 }
Exemplo n.º 22
0
 function ProcessTextTTF($draw_it, $font, $angle, $x, $y, $color, $text, $h_factor, $v_factor)
 {
     # Extract font parameters (see SetFontTTF):
     $font_file = $font['font'];
     $font_size = $font['size'];
     $font_height = $font['height'];
     $line_spacing = $this->GetLineSpacing($font);
     # Break up the text into lines, trim whitespace.
     # Calculate the total width and height of the text box at 0 degrees.
     # Save the trimmed lines and their widths for later when drawing.
     # To get uniform spacing, don't use the actual line heights.
     # Total height = Font-specific line heights plus inter-line spacing.
     # Total width = width of widest line.
     # Last Line Descent is the offset from the bottom to the text baseline.
     # Note: For some reason, ImageTTFBBox uses (-1,-1) as the reference point.
     #   So 1+bbox[1] is the baseline to bottom distance.
     $total_width = 0;
     $lastline_descent = 0;
     foreach (explode("\n", $text) as $each_line) {
         $lines[] = $line = trim($each_line);
         $bbox = ImageTTFBBox($font_size, 0, $font_file, $line);
         $line_widths[] = $width = $bbox[2] - $bbox[0];
         if ($width > $total_width) {
             $total_width = $width;
         }
         $lastline_descent = 1 + $bbox[1];
     }
     $n_lines = count($lines);
     $total_height = $n_lines * $font_height + ($n_lines - 1) * $line_spacing;
     # Calculate the rotation matrix for the text's angle. Remember that GD points Y down,
     # so the sin() terms change sign.
     $theta = deg2rad($angle);
     $cos_t = cos($theta);
     $sin_t = sin($theta);
     $r00 = $cos_t;
     $r01 = $sin_t;
     $r10 = -$sin_t;
     $r11 = $cos_t;
     # Make a bounding box of the right size, with upper left corner at (0,0).
     # By convention, the point order is: LL, LR, UR, UL.
     # Note this is still working with the text at 0 degrees.
     # When sizing text (SizeText), use the overall size with descenders.
     #   This tells the caller how much room to leave for the text.
     # When drawing text (DrawText), use the size without descenders - that
     #   is, down to the baseline. This is for accurate positioning.
     $b[0] = 0;
     if ($draw_it) {
         $b[1] = $total_height;
     } else {
         $b[1] = $total_height + $lastline_descent;
     }
     $b[2] = $total_width;
     $b[3] = $b[1];
     $b[4] = $total_width;
     $b[5] = 0;
     $b[6] = 0;
     $b[7] = 0;
     # Rotate the bounding box, then offset to the reference point:
     for ($i = 0; $i < 8; $i += 2) {
         $x_b = $b[$i];
         $y_b = $b[$i + 1];
         $c[$i] = $x + $r00 * $x_b + $r01 * $y_b;
         $c[$i + 1] = $y + $r10 * $x_b + $r11 * $y_b;
     }
     # Get an orthogonal (aligned with X and Y axes) bounding box around it, by
     # finding the min and max X and Y:
     $bbox_ref_x = $bbox_max_x = $c[0];
     $bbox_ref_y = $bbox_max_y = $c[1];
     for ($i = 2; $i < 8; $i += 2) {
         $x_b = $c[$i];
         if ($x_b < $bbox_ref_x) {
             $bbox_ref_x = $x_b;
         } elseif ($bbox_max_x < $x_b) {
             $bbox_max_x = $x_b;
         }
         $y_b = $c[$i + 1];
         if ($y_b < $bbox_ref_y) {
             $bbox_ref_y = $y_b;
         } elseif ($bbox_max_y < $y_b) {
             $bbox_max_y = $y_b;
         }
     }
     $bbox_width = $bbox_max_x - $bbox_ref_x;
     $bbox_height = $bbox_max_y - $bbox_ref_y;
     if (!$draw_it) {
         # Return the bounding box, rounded up (so it always contains the text):
         return array((int) ceil($bbox_width), (int) ceil($bbox_height));
     }
     $interline_step = $font_height + $line_spacing;
     // Line-to-line step
     # Calculate the offsets from the supplied reference point to the
     # upper-left corner of the text.
     # Start at the reference point at the upper left corner of the bounding
     # box (bbox_ref_x, bbox_ref_y) then adjust it for the 9 point alignment.
     # h,v_factor are 0,0 for top,left, .5,.5 for center,center, 1,1 for bottom,right.
     #    $off_x = $bbox_ref_x + $bbox_width * $h_factor - $x;
     #    $off_y = $bbox_ref_y + $bbox_height * $v_factor - $y;
     # Then use that offset to calculate back to the supplied reference point x, y
     # to get the text base point.
     #    $qx = $x - $off_x;
     #    $qy = $y - $off_y;
     # Reduces to:
     $qx = 2 * $x - $bbox_ref_x - $bbox_width * $h_factor;
     $qy = 2 * $y - $bbox_ref_y - $bbox_height * $v_factor;
     # Check for debug callback. Don't calculate bounding box unless it is wanted.
     if ($this->GetCallback('debug_textbox')) {
         # Calculate the orthogonal bounding box coordinates for debug testing.
         # qx, qy is upper left corner relative to the text.
         # Calculate px,py: upper left corner (absolute) of the bounding box.
         # There are 4 equation sets for this, depending on the quadrant:
         if ($sin_t > 0) {
             if ($cos_t > 0) {
                 # Quadrant: 0d - 90d:
                 $px = $qx;
                 $py = $qy - $total_width * $sin_t;
             } else {
                 # Quadrant: 90d - 180d:
                 $px = $qx + $total_width * $cos_t;
                 $py = $qy - $bbox_height;
             }
         } else {
             if ($cos_t < 0) {
                 # Quadrant: 180d - 270d:
                 $px = $qx - $bbox_width;
                 $py = $qy + $total_height * $cos_t;
             } else {
                 # Quadrant: 270d - 360d:
                 $px = $qx + $total_height * $sin_t;
                 $py = $qy;
             }
         }
         $this->DoCallback('debug_textbox', $px, $py, $bbox_width, $bbox_height);
     }
     # Since alignment is applied after rotation, which parameter is used
     # to control alignment of each line within the text box varies with
     # the angle.
     #   Angle (degrees):       Line alignment controlled by:
     #  -45 < angle <= 45          h_align
     #   45 < angle <= 135         reversed v_align
     #  135 < angle <= 225         reversed h_align
     #  225 < angle <= 315         v_align
     if ($cos_t >= $sin_t) {
         if ($cos_t >= -$sin_t) {
             $line_align_factor = $h_factor;
         } else {
             $line_align_factor = $v_factor;
         }
     } else {
         if ($cos_t >= -$sin_t) {
             $line_align_factor = 1 - $v_factor;
         } else {
             $line_align_factor = 1 - $h_factor;
         }
     }
     # Now we have the start point, spacing and in-line alignment factor.
     # We are finally ready to start drawing the text, line by line.
     for ($i = 0; $i < $n_lines; $i++) {
         # For drawing TTF text, the reference point is the left edge of the
         # text baseline (not the lower left corner of the bounding box).
         # The following also adjusts for horizontal (relative to
         # the text) alignment of the current line within the box.
         # What is happening is rotation of this vector by the text angle:
         #    (x = (total_width - line_width) * factor, y = font_height)
         $width_factor = ($total_width - $line_widths[$i]) * $line_align_factor;
         $rx = $qx + $r00 * $width_factor + $r01 * $font_height;
         $ry = $qy + $r10 * $width_factor + $r11 * $font_height;
         # Finally, draw the text:
         ImageTTFText($this->img, $font_size, $angle, $rx, $ry, $color, $font_file, $lines[$i]);
         # Step to position of next line.
         # This is a rotation of (x=0,y=height+line_spacing) by $angle:
         $qx += $r01 * $interline_step;
         $qy += $r11 * $interline_step;
     }
     return True;
 }
Exemplo n.º 23
0
$im = ImageCreateTrueColor($imgmaxxroom, $imgmaxyroom);
$black = ImageColorAllocate($im, 0, 0, 0);
$bg1p = ImageColorAllocate($im, $bg1_R, $bg1_G, $bg1_B);
$bg2p = ImageColorAllocate($im, $buttonBg_R, $buttonBg_G, $buttonBg_B);
$bg3p = ImageColorAllocate($im, $fontcol_grap_R, $fontcol_grap_G, $fontcol_grap_B);
$white = ImageColorAllocate($im, 255, 255, 255);
$gray = ImageColorAllocate($im, 133, 133, 133);
$red = ImageColorAllocate($im, 255, 0, 0);
$green = ImageColorAllocate($im, 0, 255, 0);
$yellow = ImageColorAllocate($im, 255, 255, 0);
$orange = ImageColorAllocate($im, 255, 230, 25);
if ($room == $showroom) {
    $imgcolor = $bg1p;
    $txtcolor = $white;
} else {
    $imgcolor = $bg2p;
    $txtcolor = $bg3p;
}
ImageFill($im, 0, 0, $imgcolor);
ImageRectangle($im, 0, 0, $imgmaxxroom - 1, $imgmaxyroom - 1, $white);
###ttf
$text = $room;
$box = @imageTTFBbox($roomfontsizetitel, 0, $fontttfb, $text);
$textwidth = abs($box[4] - $box[0]);
$textheight = abs($box[5] - $box[1]);
$xcord = $imgmaxxroom / 2 - $textwidth / 2 - 2;
#	$ycord = ($imgmaxyroom/2)+($textheight/2);
$ycord = $imgmaxyroom / 3 + $roomfontsizetitel;
ImageTTFText($im, $roomfontsizetitel, 0, $xcord, $ycord, $txtcolor, $fontttfb, $text);
header("Content-type: image/png");
imagePng($im);
Exemplo n.º 24
0
 public function genBarCode($code_id)
 {
     $text = $code_id;
     $font_size = 50;
     $height = 80;
     $width = 100;
     $im = ImageCreate($width, $height);
     $grey = ImageColorAllocate($im, 230, 230, 230);
     $black = ImageColorAllocate($im, 0, 0, 0);
     $text_bbox = ImageTTFBBox($font_size, 0, "font/FRE3OF9X.TTF", $text);
     $image_centerx = $width / 2;
     $image_centery = $height / 2;
     $text_x = $image_centerx - round($text_bbox[4] / 2);
     $text_y = $image_centery;
     ImageTTFText($im, $font_size, 0, $text_x, $text_y, $black, "font/FRE3OF9X.TTF", $text);
     ImagePng($im, "barcode/bc_{$code_id}.png");
     ImageDestroy($im);
     //echo "<img src=image.png>";
     /*
               $str="1234";
               putenv('GDFONTPATH=' . realpath('.'));
               $font = "FRE3OF9X.TTF";
               $image = imagecreate(100,30);
               $bg = imagecolorallocate($image,100,220,220);
               $black = imagecolorallocate($image, 0, 0, 0);
               imagettftext($image,28,0,2,25,$black,$font,$str);
               header("Content-type:image/png");
               imagepng($image);
               imagedestroy($image); */
 }
Exemplo n.º 25
0
 function make_captcha($captcha_text)
 {
     // create Image and set the apropriate function depending on GD-Version & websafecolor-value
     if ($this->gd_version >= 2 && !$this->websafecolors) {
         $func1 = 'imagecreatetruecolor';
         $func2 = 'imagecolorallocate';
     } else {
         $func1 = 'imageCreate';
         $func2 = 'imagecolorclosest';
     }
     $image = $func1($this->lx, $this->ly);
     // Set background color
     $this->random_color(224, 255);
     $back = @imagecolorallocate($image, $this->r, $this->g, $this->b);
     @ImageFilledRectangle($image, 0, 0, $this->lx, $this->ly, $back);
     // allocates the 216 websafe color palette to the image
     if ($this->gd_version < 2 || $this->websafecolors) {
         $this->makeWebsafeColors($image);
     }
     // fill with noise or grid
     if ($this->nb_noise > 0) {
         // random characters in background with random position, angle, color
         for ($i = 0; $i < $this->nb_noise; ++$i) {
             mt_srand((double) microtime() * 1000000);
             $size = mt_rand((int) ($this->minsize / 2.3), (int) ($this->maxsize / 1.7));
             mt_srand((double) microtime() * 1000000);
             $angle = mt_rand(0, 360);
             mt_srand((double) microtime() * 1000000);
             $x = mt_rand(0, $this->lx);
             mt_srand((double) microtime() * 1000000);
             $y = mt_rand(0, (int) ($this->ly - $size / 5));
             $this->random_color(160, 224);
             $color = $func2($image, $this->r, $this->g, $this->b);
             mt_srand((double) microtime() * 1000000);
             $text = chr(mt_rand(45, 250));
             @ImageTTFText($image, $size, $angle, $x, $y, $color, $this->change_ttf(), $text);
         }
     } else {
         // generate grid
         for ($i = 0; $i < $this->lx; $i += (int) $this->minsize) {
             $this->random_color(160, 224);
             $color = $func2($image, $this->r, $this->g, $this->b);
             @imageline($image, $i, 0, $i, $this->ly, $color);
         }
         for ($i = 0; $i < $this->ly; $i += (int) $this->minsize) {
             $this->random_color(160, 224);
             $color = $func2($image, $this->r, $this->g, $this->b);
             @imageline($image, 0, $i, $this->lx, $i, $color);
         }
     }
     // generate Text
     $x = (int) ($this->lx / ($this->chars + 10));
     $y = (int) ($this->maxsize * 1.5);
     for ($i = 0; isset($captcha_text[$i]); ++$i) {
         $text = strtoupper(substr($captcha_text, $i, 1));
         mt_srand((double) microtime() * 1000000);
         $angle = mt_rand(-$this->maxrotation, $this->maxrotation);
         //			$angle=0;
         $size = mt_rand($this->minsize, $this->maxsize);
         $this->random_color(0, 127);
         $color = $func2($image, $this->r, $this->g, $this->b);
         $this->random_color(0, 127);
         $shadow = $func2($image, $this->r + 127, $this->g + 127, $this->b + 127);
         @ImageTTFText($image, $size, $angle, $x + (int) ($size / 15), $y, $shadow, $this->change_ttf(), $text);
         @ImageTTFText($image, $size, $angle, $x, $y - (int) ($size / 15), $color, $this->ttf_file, $text);
         $x += (int) ($size + $this->minsize / 5);
     }
     @imagejpeg($image, '', $this->jpegquality);
     @imagedestroy($image);
 }
Exemplo n.º 26
0
<?php

require_once "include/time.inc.php";
require_once "include/basic.lib.php";
$now = getUgaAggaTime(time());
$time = $now['day'] . ". " . unhtmlentities(getMonthName($now['month'])) . ", " . $now['year'] . ". Jahr";
$timelen = strlen($time);
$size = 11;
if ($timelen > 18) {
    $size = 8;
}
$x = 95 - $timelen / 2 * $size;
if ($x < 0) {
    $x = 0;
}
$im_bg = @imagecreate(185, 32);
$im_fg = @imagecreate(185, 32);
$background_color = ImageColorAllocate($im_bg, 255, 255, 255);
$background_color = ImageColorAllocate($im_fg, 255, 255, 255);
$text_color = ImageColorAllocate($im_fg, 0, 0, 0);
ImageTTFText($im_fg, $size, 0, $x, 18, -$text_color, "aniron.ttf", $time);
imagecolortransparent($im_fg, $background_color);
imagecolortransparent($im_bg, $background_color);
imagecopy($im_bg, $im_fg, 0, 0, 0, 0, 185, 32);
header("Content-type: image/png");
ImagePNG($im_bg);
Exemplo n.º 27
0
 public function render($runData)
 {
     $this->TtfFolder = WIKIDOT_ROOT . '/lib/bitstream/';
     $runData->setScreenTemplate(null);
     // this assures no other output will be generated; templating service will NOT run
     $key = $runData->getParameterList()->getParameterValue("key");
     if ($key == null || $key == '') {
         $key = 'captchaCode';
     }
     $ivcode = $runData->sessionGet($key);
     $image = imagecreatetruecolor($this->lx, $this->ly);
     $this->random_color(224, 255);
     $back = @imagecolorallocate($image, $this->r, $this->g, $this->b);
     ImageFilledRectangle($image, 0, 0, $this->lx, $this->ly, $back);
     if ($this->_noise > 0) {
         // random characters in background with random position, angle, color
         for ($i = 0; $i < $this->_noise; $i++) {
             srand((double) microtime() * 1000000);
             $size = intval(rand((int) ($this->_minsize / 2.3), (int) ($this->_maxsize / 1.7)));
             srand((double) microtime() * 1000000);
             $angle = intval(rand(0, 360));
             srand((double) microtime() * 1000000);
             $x = intval(rand(0, $this->lx));
             srand((double) microtime() * 1000000);
             $y = intval(rand(0, (int) ($this->ly - $size / 5)));
             $this->random_color(160, 224);
             $color = imagecolorallocate($image, $this->r, $this->g, $this->b);
             srand((double) microtime() * 1000000);
             $text = chr(intval(rand(45, 250)));
             ImageTTFText($image, $size, $angle, $x, $y, $color, $this->changeTtf(), $text);
         }
     } else {
         // generate grid
         for ($i = 0; $i < $this->lx; $i += (int) ($this->_minsize / 1.5)) {
             $this->random_color(160, 224);
             $color = imagecolorallocate($image, $this->r, $this->g, $this->b);
             imageline($image, $i, 0, $i, $this->ly, $color);
         }
         for ($i = 0; $i < $this->ly; $i += (int) ($this->_minsize / 1.8)) {
             $this->random_color(160, 224);
             $color = imagecolorallocate($image, $this->r, $this->g, $this->b);
             imageline($image, 0, $i, $this->lx, $i, $color);
         }
     }
     // generate Text
     for ($i = 0, $x = intval(rand($this->_minsize, $this->_maxsize)); $i < strlen($ivcode); $i++) {
         $text = strtoupper(substr($ivcode, $i, 1));
         srand((double) microtime() * 1000000);
         $angle = intval(rand($this->maxrotation * -1, $this->maxrotation));
         srand((double) microtime() * 1000000);
         $size = intval(rand($this->_minsize, $this->_maxsize));
         srand((double) microtime() * 1000000);
         $y = intval(rand((int) ($size * 1.5), (int) ($this->ly - $size / 7)));
         $this->random_color(0, 127);
         $color = imagecolorallocate($image, $this->r, $this->g, $this->b);
         $this->random_color(0, 127);
         $shadow = imagecolorallocate($image, $this->r + 127, $this->g + 127, $this->b + 127);
         ImageTTFText($image, $size, $angle, $x + (int) ($size / 15), $y, $shadow, $this->changeTtf(), $text);
         ImageTTFText($image, $size, $angle, $x, $y - (int) ($size / 15), $color, $this->TtfFile, $text);
         $x += (int) ($size + $this->_minsize / 5);
     }
     header("Content-type: image/png");
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     // always modified
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     // HTTP/1.1
     header("Cache-Control: no-store, no-cache, must-revalidate");
     header("Cache-Control: post-check=0, pre-check=0", false);
     // HTTP/1.0
     header("Pragma: no-cache");
     imagepng($image);
     imagedestroy($image);
 }
 /** @private **/
 function make_captcha($private_key = '')
 {
     if ($private_key == '') {
         $private_key = $this->generate_keypair();
     }
     // set dimension of image
     $this->lx = (strlen($private_key) + 1) * (int) (($this->maxsize + $this->minsize) / 1.5);
     $this->ly = (int) (2.4 * $this->maxsize);
     if ($this->debug) {
         echo "\n<br>-b2evo-Captcha-Debug: Set image dimension to: (" . $this->lx . ' x ' . $this->ly . ')';
     }
     if ($this->debug) {
         echo "\n<br>-Captcha-Debug: Generate private key: ({$private_key})";
     }
     // set number of noise-chars for background if is enabled
     $this->nb_noise = $this->noise ? strlen($private_key) * $this->noisefactor : 0;
     if ($this->debug) {
         echo "\n<br>-b2evo-Captcha-Debug: Set number of noise characters to: (" . $this->nb_noise . ')';
     }
     // create Image and set the apropriate function depending on GD-Version & websafecolor-value
     if ($this->gd_version >= 2 && !$this->websafecolors) {
         $func1 = 'imagecreatetruecolor';
         $func2 = 'imagecolorallocate';
     } else {
         $func1 = 'imageCreate';
         $func2 = 'imagecolorclosest';
     }
     $image = $func1($this->lx, $this->ly);
     if ($this->debug) {
         echo "\n<br>-Captcha-Debug: Generate ImageStream with: ({$func1}())";
     }
     if ($this->debug) {
         echo "\n<br>-Captcha-Debug: For colordefinitions we use: ({$func2}())";
     }
     // Set Backgroundcolor
     $this->random_color(224, 255);
     $back = @imagecolorallocate($image, $this->r, $this->g, $this->b);
     @ImageFilledRectangle($image, 0, 0, $this->lx, $this->ly, $back);
     if ($this->debug) {
         echo "\n<br>-Captcha-Debug: We allocate one color for Background: (" . $this->r . '-' . $this->g . '-' . $this->b . ')';
     }
     // allocates the 216 websafe color palette to the image
     if ($this->gd_version < 2 || $this->websafecolors) {
         $this->makeWebsafeColors($image);
     }
     // fill with noise or grid
     if ($this->nb_noise > 0) {
         // random characters in background with random position, angle, color
         if ($this->debug) {
             echo "\n<br>-Captcha-Debug: Fill background with noise: (" . $this->nb_noise . ')';
         }
         for ($i = 0; $i < $this->nb_noise; $i++) {
             $size = intval(mt_rand((int) ($this->minsize / 2.3), (int) ($this->maxsize / 1.7)));
             $angle = intval(mt_rand(0, 360));
             $x = intval(mt_rand(0, $this->lx));
             $y = intval(mt_rand(0, (int) ($this->ly - $size / 5)));
             $this->random_color(160, 224);
             $color = $func2($image, $this->r, $this->g, $this->b);
             $text = chr(intval(mt_rand(45, 250)));
             @ImageTTFText($image, $size, $angle, $x, $y, $color, $this->change_TTF(), $text);
         }
     } else {
         // generate grid
         if ($this->debug) {
             echo "\n<br>-Captcha-Debug: Fill background with x-gridlines: (" . (int) ($this->lx / (int) ($this->minsize / 1.5)) . ')';
         }
         for ($i = 0; $i < $this->lx; $i += (int) ($this->minsize / 1.5)) {
             $this->random_color(160, 224);
             $color = $func2($image, $this->r, $this->g, $this->b);
             @imageline($image, $i, 0, $i, $this->ly, $color);
         }
         if ($this->debug) {
             echo "\n<br>-Captcha-Debug: Fill background with y-gridlines: (" . (int) ($this->ly / (int) ($this->minsize / 1.8)) . ')';
         }
         for ($i = 0; $i < $this->ly; $i += (int) ($this->minsize / 1.8)) {
             $this->random_color(160, 224);
             $color = $func2($image, $this->r, $this->g, $this->b);
             @imageline($image, 0, $i, $this->lx, $i, $color);
         }
     }
     // generate Text
     if ($this->debug) {
         echo "\n<br>-Captcha-Debug: Fill forground with chars and shadows: (" . $this->chars . ')';
     }
     for ($i = 0, $x = intval(mt_rand($this->minsize, $this->maxsize)); $i < strlen($private_key); $i++) {
         $text = substr($private_key, $i, 1);
         $angle = intval(mt_rand($this->maxrotation * -1, $this->maxrotation));
         $size = intval(mt_rand($this->minsize, $this->maxsize));
         $y = intval(mt_rand((int) ($size * 1.5), (int) ($this->ly - $size / 7)));
         $this->random_color(0, 127);
         $color = $func2($image, $this->r, $this->g, $this->b);
         $this->random_color(0, 127);
         $shadow = $func2($image, $this->r + 127, $this->g + 127, $this->b + 127);
         @ImageTTFText($image, $size, $angle, $x + (int) ($size / 15), $y, $shadow, $this->change_TTF(), $text);
         @ImageTTFText($image, $size, $angle, $x, $y - (int) ($size / 15), $color, $this->TTF_file, $text);
         $x += (int) ($size + $this->minsize / 5);
     }
     @ImageJPEG($image, $this->get_filename(), $this->jpegquality);
     $res = file_exists($this->get_filename());
     if ($this->debug) {
         echo "\n<br>-Captcha-Debug: Save Image with quality [" . $this->jpegquality . '] as (' . $this->get_filename() . ') returns: (' . ($res ? 'TRUE' : 'FALSE') . ')';
     }
     @ImageDestroy($image);
     if ($this->debug) {
         echo "\n<br>-Captcha-Debug: Destroy Imagestream.";
     }
     if (!$res) {
         die('Unable to save captcha-image.');
     }
 }
Exemplo n.º 29
0
 function displayImage()
 {
     //{{{
     $data = array();
     $image_width = $image_height = 0;
     for ($i = 0; $i < $this->length; $i++) {
         //$char = substr($src, mt_rand(0,$srclen), 1);
         //$this->key .= $char;
         $char = $this->key[$i];
         $size = mt_rand($this->min_font_size, $this->max_font_size);
         $angle = mt_rand($this->min_angle, $this->max_angle);
         $bbox = ImageTTFBBox($size, $angle, $this->fontFileName, $char);
         $char_width = max($bbox[2], $bbox[4]) - min($bbox[0], $bbox[6]);
         $char_height = max($bbox[1], $bbox[3]) - min($bbox[7], $bbox[5]);
         $image_width += $char_width + $this->char_padding;
         $image_height = max($image_height, $char_height);
         $data[] = array('char' => $char, 'size' => $size, 'angle' => $angle, 'height' => $char_height, 'width' => $char_width);
     }
     $image_width += $this->x_padding * 2;
     $image_height = $image_height * 1.5 + 2;
     $im = ImageCreate($image_width, $image_height);
     $r = 51 * mt_rand(4, 5);
     $g = 51 * mt_rand(4, 5);
     $b = 51 * mt_rand(4, 5);
     $color_bg = ImageColorAllocate($im, $r, $g, $b);
     $r = 51 * mt_rand(3, 4);
     $g = 51 * mt_rand(3, 4);
     $b = 51 * mt_rand(3, 4);
     $color_line0 = ImageColorAllocate($im, $r, $g, $b);
     $r = 51 * mt_rand(3, 4);
     $g = 51 * mt_rand(3, 4);
     $b = 51 * mt_rand(3, 4);
     $color_line1 = ImageColorAllocate($im, $r, $g, $b);
     $r = 51 * mt_rand(1, 2);
     $g = 51 * mt_rand(1, 2);
     $b = 51 * mt_rand(1, 2);
     $color_text = ImageColorAllocate($im, $r, $g, $b);
     $color_border = ImageColorAllocate($im, 0, 0, 0);
     // make the random background lines
     for ($l = 0; $l < 10; $l++) {
         $c = 'color_line' . $l % 2;
         $lx = mt_rand(0, $image_width + $image_height);
         $lw = mt_rand(0, 3);
         if ($lx > $image_width) {
             $lx -= $image_width;
             ImageFilledRectangle($im, 0, $lx, $image_width - 1, $lx + $lw, ${$c});
         } else {
             ImageFilledRectangle($im, $lx, 0, $lx + $lw, $image_height - 1, ${$c});
         }
     }
     // output each character
     $pos_x = $this->x_padding + $this->char_padding / 2;
     foreach ($data as $d) {
         $pos_y = ($image_height + $d['height']) / 2;
         ImageTTFText($im, $d['size'], $d['angle'], $pos_x, $pos_y, $color_text, $this->fontFileName, $d['char']);
         $pos_x += $d['width'] + $this->char_padding;
     }
     // a nice border
     ImageRectangle($im, 0, 0, $image_width - 1, $image_height - 1, $color_border);
     // display it
     switch ($this->output_type) {
         case 'jpeg':
             Header('Content-type: image/jpeg');
             ImageJPEG($im, NULL, 100);
             break;
         case 'png':
         default:
             Header('Content-type: image/png');
             ImagePNG($im);
             break;
     }
     ImageDestroy($im);
 }
Exemplo n.º 30
0
 function make_captcha($noise = true)
 {
     $private_key = $this->generate_private();
     $image = imagecreatetruecolor($this->lx, $this->ly);
     $back = ImageColorAllocate($image, rand(224, 255), rand(224, 255), rand(224, 255));
     ImageFilledRectangle($image, 0, 0, $this->lx, $this->ly, $back);
     if ($noise) {
         // rand characters in background with random position, angle, color
         for ($i = 0; $i < $this->nb_noise; $i++) {
             $size = rand(6, 14);
             $angle = rand(0, 360);
             $x = rand(10, $this->lx - 10);
             $y = rand(0, $this->ly - 5);
             $color = imagecolorallocate($image, rand(160, 224), rand(160, 224), rand(160, 224));
             $text = chr(rand(45, 127));
             ImageTTFText($image, $size, $angle, $x, $y, $color, $this->font_file, $text);
         }
     } else {
         // random grid color
         for ($i = 0; $i < $this->lx; $i += 10) {
             $color = imagecolorallocate($image, rand(160, 224), rand(160, 224), rand(160, 224));
             imageline($image, $i, 0, $i, $this->ly, $color);
         }
         for ($i = 0; $i < $this->ly; $i += 10) {
             $color = imagecolorallocate($image, intval(rand(160, 224)), intval(rand(160, 224)), intval(rand(160, 224)));
             imageline($image, 0, $i, $this->lx, $i, $color);
         }
     }
     // private text to read
     for ($i = 0, $x = 5; $i < $this->long; $i++) {
         $r = rand(0, 128);
         $g = rand(0, 128);
         $b = rand(0, 128);
         $color = ImageColorAllocate($image, $r, $g, $b);
         $shadow = ImageColorAllocate($image, $r + 128, $g + 128, $b + 128);
         $size = rand(12, 17);
         $angle = rand(-30, 30);
         $text = strtoupper(substr($private_key, $i, 1));
         ImageTTFText($image, $size, $angle, $x + 2, 26, $shadow, $this->font_file, $text);
         ImageTTFText($image, $size, $angle, $x, 24, $color, $this->font_file, $text);
         $x += $size + 2;
     }
     if ($this->imagetype == 'jpg') {
         imagejpeg($image, $this->get_filename(), 100);
     } else {
         imagepng($image, $this->get_filename());
     }
     ImageDestroy($image);
 }