• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP imagettftext函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中imagettftext函数的典型用法代码示例。如果您正苦于以下问题:PHP imagettftext函数的具体用法?PHP imagettftext怎么用?PHP imagettftext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了imagettftext函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: generate

 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);
 }
开发者ID:reang,项目名称:Dingo-Framework,代码行数:35,代码来源:capcha.php


示例2: verifyImage

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);
}
开发者ID:hiden2,项目名称:shopImooc-1,代码行数:35,代码来源:image.func.php


示例3: generateImage

function generateImage($certiImage, $posXString, $posYString, $posX2String, $posY2String, $valueString)
{
    $certiPath = dirname(__FILE__);
    $certiImage = imagecreatefromjpeg($certiPath . '/certi_images/' . $certiImage);
    $color = imagecolorallocate($certiImage, 0, 0, 0);
    //black
    //		$whiteBackground = imagecolorallocate($background, 255, 255, 255);
    //	$imagefill($certiImage,0,0,$whiteBackground);
    $rotatedImage = imagerotate($certiImage, 90, $color);
    //rotate certificate
    $font = $certiPath . '/fonts/odstemplik.otf';
    $posXArray = explode("::", $posXString);
    $posYArray = explode("::", $posYString);
    $posX2Array = explode("::", $posX2String);
    $posY2Array = explode("::", $posY2String);
    $valuesArray = explode("::", $valueString);
    //	error_log(print_r($valuesArray));
    for ($i = 0; $i < sizeof($valuesArray); $i++) {
        $lineWidth = $posYArray[$i] - $posY2Array[$i];
        $font_size = 90;
        do {
            $p = imagettfbbox($font_size, 0, $font, $valuesArray[$i]);
            $textWidth = $p[2] - $p[0];
            $font_size--;
            //			   error_log($textWidth);
        } while ($textWidth >= $lineWidth);
        $y = ($lineWidth - $textWidth) / 2;
        imagettftext($rotatedImage, $font_size, 90, $posXArray[$i], $posYArray[$i] - $y, $color, $font, $valuesArray[$i]);
    }
    ob_start();
    imagejpeg($rotatedImage);
    $actual_image = base64_encode(ob_get_contents());
    ob_end_clean();
    return "data:image/png;base64," . $actual_image;
}
开发者ID:ksb1712,项目名称:pragyan,代码行数:35,代码来源:events_certi_image2.php


示例4: show_captcha

 public function show_captcha()
 {
     if (session_id() == "") {
         session_name("CAKEPHP");
         session_start();
     }
     $vendor_path = App::path('Vendor');
     $path = $vendor_path[0] . 'captcha';
     $imgname = 'bg.jpg';
     $imgpath = $path . DS . 'images' . DS . $imgname;
     $captchatext = md5(time());
     $captchatext = substr($captchatext, 0, 5);
     $_SESSION['captcha'] = $captchatext;
     if (file_exists($imgpath)) {
         $im = imagecreatefromjpeg($imgpath);
         $grey = imagecolorallocate($im, rand(1, 128), 128, 128);
         $font = $path . DS . 'fonts' . DS . '3D_Noise.ttf';
         imagettftext($im, 36, 0, 0, 55, $grey, $font, $captchatext);
         header('Content-Type: image/jpeg');
         header("Cache-control: private, no-cache");
         header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
         header("Pragma: no-cache");
         imagejpeg($im);
         imagedestroy($im);
         ob_flush();
         flush();
     } else {
         echo 'captcha error';
         exit;
     }
 }
开发者ID:BGCX067,项目名称:ezord-svn-to-git,代码行数:31,代码来源:captcha.php


示例5: calcFontSizeAddText

 public function calcFontSizeAddText($text, $parts, $whole, $angle = 0)
 {
     $imgWidth = imagesx($this->image);
     $imgHeight = imagesy($this->image);
     if (strlen($text) > 0) {
         $fontsize = $imgWidth / strlen($text);
         $textBox = imagettfbbox($fontsize, 0, $this->font, $text);
         /*
         				[0] lower left X coordinate
         				[1] lower left Y coordinate
         				[2] lower right X coordinate
         				[3] lower right Y coordinate
         				[4] upper right X coordinate
         				[5] upper right Y coordinate
         				[6] upper left X coordinate
         				[7] upper left Y coordinate
         */
         $textBoxLowerLeftX = $textBox[0];
         $textBoxLowerRightX = $textBox[2];
         $textBoxLowerLeftY = $textBox[1];
         $textBoxUpperLeftY = $textBox[7];
         $textHeight = $textBoxUpperLeftY - $textBoxLowerLeftY;
         $x = ceil(($imgWidth - $textBoxLowerRightX - $textBoxLowerLeftX) / 2);
         $y = ($imgHeight / $whole - $textHeight / $whole) * $parts;
         imagettftext($this->image, $fontsize, $angle, $x, $y, $this->color, $this->font, $text);
     }
 }
开发者ID:henceee,项目名称:1DV608_project,代码行数:27,代码来源:ImageText.php


示例6: smart_spam

function smart_spam($code)
{
    @putenv('GDFONTPATH=' . realpath('.'));
    $font = 'FONT.TTF';
    // antispam image height
    $height = 40;
    // antispam image width
    $width = 110;
    $font_size = $height * 0.6;
    $image = @imagecreate($width, $height);
    $background_color = @imagecolorallocate($image, 255, 255, 255);
    $noise_color = @imagecolorallocate($image, 20, 40, 100);
    /* add image noise */
    for ($i = 0; $i < $width * $height / 4; $i++) {
        @imageellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
    }
    /* render text */
    $text_color = @imagecolorallocate($image, 20, 40, 100);
    @imagettftext($image, $font_size, 0, 7, 29, $text_color, $font, $code) or die('Cannot render TTF text.');
    //output image to the browser *//*
    header('Content-Type: image/png');
    @imagepng($image) or die('imagepng error!');
    @imagedestroy($image);
    exit;
}
开发者ID:JozefAB,项目名称:neoacu,代码行数:25,代码来源:captcha.php


示例7: createCode

 function createCode($len = 4)
 {
     $width = 100;
     $height = 50;
     $size = 22;
     //字体大小
     $font = ROOT_PATH . '/static/font/arial.ttf';
     //字体
     $img = imagecreatetruecolor($width, $height);
     //创建画布
     $bgimg = imagecreatefromjpeg(ROOT_PATH . '/static/background/' . rand(1, 5) . '.jpg');
     //生成背景图片
     $bg_x = rand(0, 100);
     //随机招贴画布起始X轴坐标
     $bg_y = rand(0, 50);
     //随机招贴画布起始Y轴坐标
     imagecopy($img, $bgimg, 0, 0, $bg_x, $bg_y, $bg_x + $width, $bg_y + $height);
     //把背景图片$bging粘贴的画布上
     $str = $this->creaStr($len);
     //字符串
     for ($i = 0, $j = 5; $i < 4; $i++) {
         $array = array(-1, 1);
         $p = array_rand($array);
         $an = $array[$p] * mt_rand(1, 10);
         //扭曲角度
         imagettftext($img, $size, $an, $j + 5, 34, imagecolorallocate($img, rand(0, 100), rand(0, 100), rand(0, 100)), $font, $str[$i]);
         //生成验证字符窜
         $j += 20;
     }
     cookie('captchacode', strtolower($str));
     header('Content-type:image/png');
     imagepng($img);
     imagedestroy($img);
 }
开发者ID:xy113,项目名称:XiangBaLaoServer,代码行数:34,代码来源:class.Captcha.php


示例8: createImageTextKod

 /**
  * 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);
 }
开发者ID:ngogiangthanh,项目名称:damtvnewversion,代码行数:45,代码来源:image.lib.php


示例9: create_image

function create_image()
{
    // hash: là mật mã
    $md5_hash = md5(rand(0, 999));
    // rand phat sinh 1 số từ 0 - 999
    // md5 sẽ mã hóa 1 số thành 1 số khác đến 32 ký tự
    $security_code = substr($md5_hash, 15, 4);
    // substr lấy 1 chuỗi con trong md5_hash, lấy từ ký tự thứ 15 và lấy 5 ký tự
    $_SESSION['security_code'] = $security_code;
    $width = 100;
    //Khai báo kích thước captcha
    $height = 30;
    $image = imagecreate($width, $height);
    $while = imagecolorallocate($image, 255, 255, 255);
    $black = imagecolorallocate($image, 0, 0, 0);
    $red = imagecolorallocate($image, 255, 255, 0);
    imagefill($image, 0, 0, $black);
    imagestring($image, 5, 30, 6, $security_code, $while);
    // 5 font size
    // 30 khoảng cách bên trái
    //khoảng cách từ trên xuống
    $captcha = imagecreatefrompng('captcha1.png');
    $font = 'arial.ttf';
    imagettftext($captcha, 23, 6, 20, 38, $black, $font, $security_code);
    header("Content-Type:image/jpeg");
    // chuyển trang web thành dạng hình jpg
    imagejpeg($captcha);
    //Tạo hình
    imagedestroy($captcha);
    // Hủy hình gốc vì đã tạo thành trang
}
开发者ID:tlcn11,项目名称:MaiTranThuy,代码行数:31,代码来源:captcha.php


示例10: getCaptcha

 /**
  * 生成验证码
  * @param int $width 验证码图片宽度.默认130
  * @param int $height 验证码图片高度.默认40
  * @param int $fontSize 验证码字体大小.默认20
  * @param int $length 验证码字符个数.默认4
  * @return string  验证码中的字符串
  */
 public static function getCaptcha($width = '130', $height = '40', $fontSize = '20', $length = '4')
 {
     $chars = '0123456789abcdefghijklmnopqrstuvwxyz';
     $randStr = substr(str_shuffle($chars), 0, $length);
     $image = imagecreatetruecolor($width, $height);
     // 定义背景色
     $bgColor = imagecolorallocate($image, 0xff, 0xff, 0xff);
     // 定义文字及边框颜色
     $blackColor = imagecolorallocate($image, 0x0, 0x0, 0x0);
     //生成矩形边框
     imagefilledrectangle($image, 0, 0, $width, $height, $bgColor);
     // 循环生成雪花点
     for ($i = 0; $i < 200; $i++) {
         $grayColor = imagecolorallocate($image, 128 + rand(0, 128), 128 + rand(0, 128), 128 + rand(0, 128));
         imagesetpixel($image, rand(1, $width - 2), rand(4, $height - 2), $grayColor);
     }
     $font = ROOT_PATH . 'resources/fonts/acidic.ttf';
     // 把随机字符串输入图片
     $i = -1;
     while (isset($randStr[++$i])) {
         $fontColor = imagecolorallocate($image, rand(0, 100), rand(0, 100), rand(0, 100));
         if (!function_exists('imagettftext')) {
             imagechar($image, $fontSize, 15 + $i * 30, rand(5, 20), $randStr[$i], $fontColor);
         } else {
             imagettftext($image, $fontSize, 0, 10 + $i * 30, rand(25, 35), $fontColor, $font, $randStr[$i]);
         }
     }
     imagepng($image);
     $image = $bgColor = $blackColor = $grayColor = $fontColor = null;
     return $randStr;
 }
开发者ID:hellocc2,项目名称:crmht,代码行数:39,代码来源:Image.php


示例11: create_captcha

 function create_captcha($time)
 {
     @session_start();
     $image;
     global $image;
     $word_1 = '';
     $word_2 = "";
     for ($i = 0; $i < 4; $i++) {
         $word_1 .= chr(rand(97, 122));
     }
     for ($i = 0; $i < 4; $i++) {
         $word_2 .= chr(rand(97, 122));
     }
     $_SESSION['random_number'] = $word_1 . ' ' . $word_2;
     $dir = './fonts/';
     $image = imagecreatetruecolor(165, 50);
     $font = "recaptchaFont.ttf";
     // font style
     $color = imagecolorallocate($image, 0, 0, 0);
     // color
     $white = imagecolorallocate($image, 255, 255, 255);
     // background color white
     imagefilledrectangle($image, 0, 0, 709, 99, $white);
     imagettftext($image, 22, 0, 5, 30, $color, $dir . $font, $_SESSION['random_number']);
     $_SESSION['count'] = $_SESSION['random_number'];
     $_SESSION['captcha_string'] = $_SESSION['random_number'];
     $images = glob("./style/captcha/*.png");
     foreach ($images as $image_to_delete) {
         @unlink($image_to_delete);
     }
     imagepng($image, "./style/captcha/" . $time . ".png");
     //return array('image'=>$image,'count'=>$_SESSION['count']);
 }
开发者ID:nationalbroadband,项目名称:nationalbroadband,代码行数:33,代码来源:captcha_helper.php


示例12: text

 /**
  * 添加文字水印
  * @$word  水印文字
  */
 public function text($word)
 {
     $textcolor = imagecolorallocate($this->info['image'], 255, 255, 255);
     $font = 'msyh.ttf';
     //imagestring($this->info['image'],2,40,40,$word,$textcolor);
     imagettftext($this->info['image'], 14, 0, 20, 20, $textcolor, $font, $word);
 }
开发者ID:JamesGoldP,项目名称:watermark,代码行数:11,代码来源:watermark.php


示例13: createCaptcha

 public function createCaptcha()
 {
     $captcha = '';
     $symbol = '0';
     $width = 420;
     $height = 70;
     $font = 'fonts/bellb.ttf';
     $fontsize = 20;
     $captchaLength = rand(1, 1);
     $im = imagecreatetruecolor($width, $height);
     $bg = imagecolorallocatealpha($im, 0, 0, 0, 127);
     imagefill($im, 0, 0, $bg);
     for ($i = 0; $i < $captchaLength; $i++) {
         $captcha .= $symbol[rand(0, strlen($symbol) - 1)];
         $x = ($width - 20) / $captchaLength * $i + 10;
         $x = rand($x, $x + 4);
         $y = $height - ($height - $fontsize) / 2;
         $curcolor = imagecolorallocate($im, rand(0, 100), rand(0, 100), rand(0, 100));
         $angle = rand(-25, 25);
         imagettftext($im, $fontsize, $angle, $x, $y, $curcolor, $font, $captcha[$i]);
     }
     session_start();
     $_SESSION['captcha'] = $captcha;
     header('Content-type: image/png');
     imagepng($im);
     imagedestroy($im);
 }
开发者ID:Arxemond777,项目名称:News,代码行数:27,代码来源:captcha.php


示例14: GetImage

 /**
  * [GetImage 生成验证码]
  */
 public function GetImage()
 {
     $this->font_name = __DIR__ . DIRECTORY_SEPARATOR . $this->font_name;
     $this->type = strtolower($this->type);
     //转小写
     $img = imagecreate($this->width, $this->height) or die("can't found GD Moudle!");
     $bg = imagecolorallocate($img, rand(0, 100), rand(0, 100), rand(0, 100));
     $font_color = imagecolorallocate($img, 255, 255, 255);
     $str = $this->GetString();
     $strinterval = floor($this->width / $this->char_num);
     $pos_y = abs(floor($this->height / 2) + floor($this->font_size / 2));
     if ($this->chinese) {
         $str_arr = str_split($str, 3);
     } else {
         $str_arr = str_split($str);
     }
     $length = mb_strlen($str, "utf-8");
     //输出文字
     for ($i = 0; $i < $length; $i++) {
         $font_color_rand = imagecolorallocate($img, rand(155, 255), rand(155, 255), rand(155, 255));
         imagettftext($img, $this->font_size, rand(-25, 25), $strinterval * $i + 3, $pos_y, $font_color_rand, $this->font_name, $str_arr[$i]);
     }
     $this->CreateLine($img);
     $this->CreatePixel($img);
     $this->img = $img;
 }
开发者ID:dearmadman,项目名称:captcha,代码行数:29,代码来源:Captcha.php


示例15: thumbnailThis

 function thumbnailThis($ruta, $img, $c_nombr, $c_vig, $c_folio)
 {
     // Set the enviroment variable for GD
     putenv('GDFONTPATH=' . realpath('.'));
     $cardId = uniqid();
     // Genera un ID único para el nombre de archivo
     while (file_exists($ruta . '/cards/' . $cardId . ".jpg")) {
         // Si el nombre existe, genera otro
         $cardId = uniqid();
         // unlink( $ruta.$img."_usuario.jpg" );
     }
     // Name the font to be used (note the lack of the .ttf extension)
     $font = 'varela';
     /*Dimensiones*/
     $c_width = 1004;
     $c_height = 1299;
     $laImagen = $img . ".jpg";
     $createdImg = imagecreatefromjpeg($ruta . $laImagen);
     /*imagejpeg($createdImg,$ruta."hola.jpg",50);*/
     $width = imagesx($createdImg);
     $height = imagesy($createdImg);
     $previous = imagecreatetruecolor($c_width, $c_height);
     imagecopyresampled($previous, $createdImg, 0, 0, 0, 0, $c_width, $c_height, $width, $height);
     /*Color en RGB*/
     $text_color = imagecolorallocate($previous, 5, 5, 5);
     /*imagestring($previous, 5, 5, 5,  'A Simple Text String', $text_color);*/
     /*Texto para la imagen
     		Imagen, tamaño, ángulo, posX, posY, color, fuente, texto*/
     imagettftext($previous, 20, 0, 130, 767, $text_color, $font, $c_nombr);
     imagettftext($previous, 20, 0, 750, 767, $text_color, $font, $c_vig);
     imagettftext($previous, 20, 0, 750, 875, $text_color, $font, $c_folio);
     imagejpeg($previous, $ruta . '/cards/' . $cardId . ".jpg", 100);
     return $ruta . '/cards/' . $cardId . ".jpg";
 }
开发者ID:jecr,项目名称:gourmet-card,代码行数:34,代码来源:write.php


示例16: getAuthImage

 function getAuthImage($text)
 {
     $this->setpin($text);
     $im_x = 160;
     $im_y = 40;
     $im = imagecreatetruecolor($im_x, $im_y);
     $text_c = ImageColorAllocate($im, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
     $tmpC0 = mt_rand(100, 255);
     $tmpC1 = mt_rand(100, 255);
     $tmpC2 = mt_rand(100, 255);
     $buttum_c = ImageColorAllocate($im, $tmpC0, $tmpC1, $tmpC2);
     imagefill($im, 16, 13, $buttum_c);
     $font = PATH_SYS_PUBLIC . 'font-awesome/fonts/verdana.ttf';
     for ($i = 0; $i < strlen($text); $i++) {
         $tmp = substr($text, $i, 1);
         $array = array(-1, 1);
         $p = array_rand($array);
         $an = $array[$p] * mt_rand(1, 10);
         //角度
         $size = 28;
         imagettftext($im, $size, $an, 15 + $i * $size, 35, $text_c, $font, $tmp);
     }
     $distortion_im = imagecreatetruecolor($im_x, $im_y);
     imagefill($distortion_im, 16, 13, $buttum_c);
     for ($i = 0; $i < $im_x; $i++) {
         for ($j = 0; $j < $im_y; $j++) {
             $rgb = imagecolorat($im, $i, $j);
             if ((int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) <= imagesx($distortion_im) && (int) ($i + 20 + sin($j / $im_y * 2 * M_PI) * 10) >= 0) {
                 imagesetpixel($distortion_im, (int) ($i + 10 + sin($j / $im_y * 2 * M_PI - M_PI * 0.1) * 4), $j, $rgb);
             }
         }
     }
     //加入干扰象素;
     $count = 160;
     //干扰像素的数量
     for ($i = 0; $i < $count; $i++) {
         $randcolor = ImageColorallocate($distortion_im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($distortion_im, mt_rand() % $im_x, mt_rand() % $im_y, $randcolor);
     }
     $rand = mt_rand(5, 30);
     $rand1 = mt_rand(15, 25);
     $rand2 = mt_rand(5, 10);
     for ($yy = $rand; $yy <= +$rand + 2; $yy++) {
         for ($px = -80; $px <= 80; $px = $px + 0.1) {
             $x = $px / $rand1;
             if ($x != 0) {
                 $y = sin($x);
             }
             $py = $y * $rand2;
             imagesetpixel($distortion_im, $px + 80, $py + $yy, $text_c);
         }
     }
     //设置文件头;
     Header("Content-type: image/JPEG");
     //以PNG格式将图像输出到浏览器或文件;
     ImagePNG($distortion_im);
     //销毁一图像,释放与image关联的内存;
     ImageDestroy($distortion_im);
     ImageDestroy($im);
 }
开发者ID:nanfs,项目名称:lt,代码行数:60,代码来源:pin.class.php


示例17: captcha

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);
}
开发者ID:brenoinojosa,项目名称:ragnarok-public,代码行数:26,代码来源:img.php


示例18: show

 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);
 }
开发者ID:mehdi-fathi,项目名称:Captcha-Component,代码行数:25,代码来源:CaptchaComponent.php


示例19: generate

 /**
  * Return captcha image
  * @param number $maxChar
  */
 public function generate($maxChar = 4)
 {
     // $characters = '23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
     $characters = 'ABCDEFGHKMNPQRST';
     $captchaText = '';
     for ($i = 0; $i < $maxChar; $i++) {
         $captchaText .= $characters[rand(0, strlen($characters) - 1)];
     }
     strtoupper(substr(md5(microtime()), 0, 7));
     \Session::put('captchaHash', \Hash::make($captchaText));
     $image = imagecreate(30 * $maxChar, 35);
     $background = imagecolorallocatealpha($image, 255, 255, 255, 1);
     $textColor = imagecolorallocatealpha($image, 206, 33, 39, 1);
     $x = 5;
     $y = 20;
     $angle = 0;
     for ($i = 0; $i < 7; $i++) {
         $fontSize = 16;
         $text = substr($captchaText, $i, 1);
         imagettftext($image, $fontSize, $angle, $x, $y, $textColor, public_path('/fonts/LibreBaskerville/librebaskerville-regular.ttf'), $text);
         $x = $x + 17 + mt_rand(1, 10);
         $y = mt_rand(18, 25);
         $angle = mt_rand(0, 20);
     }
     header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
     header('Pragma: no-cache');
     header('Content-type: image/jpeg');
     imagejpeg($image, null, 100);
     imagedestroy($image);
 }
开发者ID:atudz,项目名称:gorabelframework,代码行数:34,代码来源:CaptchaLibrary.php


示例20: __construct

 public function __construct($width = '120', $height = '40', $characters = '6')
 {
     $code = $this->generateCode($characters);
     /* font size will be 75% of the image height */
     $font_size = $height * 0.75;
     $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $background_color = imagecolorallocate($image, 255, 255, 255);
     $text_color = imagecolorallocate($image, 20, 40, 100);
     $noise_color = imagecolorallocate($image, 100, 120, 180);
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     /* generate random lines in background */
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     /* create textbox and add text */
     $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
     /* output captcha image to browser */
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
     /* @var $CI My_Controller */
     $CI = get_instance();
     $CI->session->set_userdata('security_code', $code);
 }
开发者ID:elshafey,项目名称:ir,代码行数:31,代码来源:capatcha.php



注:本文中的imagettftext函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP imagetypes函数代码示例发布时间:2022-05-15
下一篇:
PHP imagettfbbox函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap