当前位置: 首页>>代码示例>>PHP>>正文


PHP imagettftext函数代码示例

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


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


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