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

PHP imagettfbbox函数代码示例

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

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



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

示例1: write_multiline_text

function write_multiline_text($image, $font_size, $color, $font, $text, $start_x, $start_y, $max_width)
{
    //split the string
    //build new string word for word
    //check everytime you add a word if string still fits
    //otherwise, remove last word, post current string and start fresh on a new line
    $words = explode(" ", $text);
    $string = "";
    $tmp_string = "";
    for ($i = 0; $i < count($words); $i++) {
        $tmp_string .= $words[$i] . " ";
        //check size of string
        $dim = imagettfbbox($font_size, 0, $font, $tmp_string);
        if ($dim[4] < $max_width) {
            $string = $tmp_string;
        } else {
            $i--;
            $tmp_string = "";
            imagettftext($image, 11, 0, $start_x, $start_y, $color, $font, $string);
            $string = "";
            $start_y += 40;
            //change this to adjust line-height. Additionally you could use the information from the "dim" array to automatically figure out how much you have to "move down"
        }
    }
    imagettftext($image, 11, 0, $start_x, $start_y, $color, $font, $string);
    //"draws" the rest of the string
}
开发者ID:notatree,项目名称:PHPClassFunctions,代码行数:27,代码来源:imagettftext1.php


示例2: generate

 public function generate()
 {
     imagesavealpha($this->_owner->image, true);
     imagealphablending($this->_owner->image, true);
     $width = $this->_owner->getImageWidth();
     $height = $this->_owner->getImageHeight();
     $white = $this->_owner->imagecolorallocate($this->_text_color);
     $data = array();
     $total_width = 0;
     for ($x = 0; $x < strlen($this->_text); $x++) {
         $data[$x]['text'] = $this->_text[$x];
         $data[$x]['font'] = $this->_arr_ttf_font[rand(0, count($this->_arr_ttf_font) - 1)];
         $data[$x]['size'] = rand($this->_text_size, $this->_text_size + $this->_text_size_random);
         $data[$x]['angle'] = $this->_text_angle_random / 2 - rand(0, $this->_text_angle_random);
         $captcha_dimensions = imagettfbbox($data[$x]['size'], $data[$x]['angle'], $data[$x]['font'], $data[$x]['text']);
         $data[$x]['width'] = abs($captcha_dimensions[2]) + $this->_text_spacing;
         $data[$x]['height'] = abs($captcha_dimensions[5]);
         $total_width += $data[$x]['width'];
     }
     $x_offset = ($width - $total_width) / 2;
     $x_pos = 0;
     $y_pos = 0;
     foreach ($data as $ld) {
         $y_pos = ($height + $ld['height']) / 2;
         imagettftext($this->_owner->image, $ld['size'], $ld['angle'], $x_offset + $x_pos, $y_pos, $white, $ld['font'], $ld['text']);
         $x_pos += $ld['width'];
     }
     return true;
 }
开发者ID:npetrovski,项目名称:php5-image,代码行数:29,代码来源:Captcha.php


示例3: player

 /**
  *
  * @param string $playername Minecraft player name
  * @param resource $avatar the rendered avatar (for example player head)
  *
  * @param string $background Image Path or Standard Value
  * @return resource the generated banner
  */
 public static function player($playername, $avatar = NULL, $background = NULL)
 {
     $canvas = MinecraftBanner::getBackgroundCanvas(self::PLAYER_WIDTH, self::PLAYER_HEIGHT, $background);
     $head_height = self::AVATAR_SIZE;
     $head_width = self::AVATAR_SIZE;
     $avater_x = self::PLAYER_PADDING;
     $avater_y = self::PLAYER_HEIGHT / 2 - self::AVATAR_SIZE / 2;
     if ($avatar == NULL) {
         $avatar = imagecreatefrompng(__DIR__ . "/img/head.png");
         imagesavealpha($avatar, true);
         imagecopy($canvas, $avatar, $avater_x, $avater_y, 0, 0, $head_width, $head_height);
     } else {
         $head_width = imagesx($avatar);
         $head_height = imagesy($avatar);
         if ($head_width > self::AVATAR_SIZE) {
             $head_width = self::AVATAR_SIZE;
         }
         if ($head_height > self::AVATAR_SIZE) {
             $head_height = self::AVATAR_SIZE;
         }
         $center_x = $avater_x + self::AVATAR_SIZE / 2 - $head_width / 2;
         $center_y = $avater_y + self::AVATAR_SIZE / 2 - $head_height / 2;
         imagecopy($canvas, $avatar, $center_x, $center_y, 0, 0, $head_width, $head_height);
     }
     $box = imagettfbbox(self::TEXT_SIZE, 0, MinecraftBanner::FONT_FILE, $playername);
     $text_width = abs($box[4] - $box[0]);
     $text_color = imagecolorallocate($canvas, 255, 255, 255);
     $remaining = self::PLAYER_WIDTH - self::AVATAR_SIZE - $avater_x - self::PLAYER_PADDING;
     $text_posX = $avater_x + self::AVATAR_SIZE + $remaining / 2 - $text_width / 2;
     $text_posY = $avater_y + self::AVATAR_SIZE / 2 + self::TEXT_SIZE / 2;
     imagettftext($canvas, self::TEXT_SIZE, 0, $text_posX, $text_posY, $text_color, MinecraftBanner::FONT_FILE, $playername);
     return $canvas;
 }
开发者ID:games647,项目名称:minecraft-banner-generator,代码行数:41,代码来源:PlayerBanner.php


示例4: create_error

 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;
 }
开发者ID:BackupTheBerlios,项目名称:viscacha-svn,代码行数:32,代码来源:class.thumbnail.php


示例5: __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


示例6: __construct

 /**
  * Generate captcha
  *
  * @param  integer  $characters        Amount of characters to draw
  * @param  integer  $width
  * @param  integer  $height
  */
 public function __construct($characters = 10, $width = 140, $height = 24)
 {
     if (!file_exists($this->font)) {
         throw new RuntimeException("Font " . $this->font . " is missing. Can't proceed.");
     }
     $this->code = $this->generateCode($characters);
     /* font size will be 75% of the image height */
     $font_size = $height * 0.7;
     $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $noise_color = imagecolorallocate($image, 255, 255, 255);
     $text_color = imagecolorallocate($image, 44, 44, 44);
     $text_color2 = imagecolorallocate($image, 244, 1, 1);
     $line_color = imagecolorallocate($image, 244, 0, 0);
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     /* generate random lines in background of text */
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     /* create textbox and add text */
     $textbox = imagettfbbox($font_size, 0, $this->font, $this->code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $this->code) or die('Error in imagettftext function');
     imagettftext($image, $font_size, 0, $x + 1, $y + 1, $text_color2, $this->font, substr($this->code, 0, 4));
     imagettftext($image, $font_size + 2, 0, $width - 50, 20, $line_color, $this->font, substr($this->code, -3));
     $this->image = $image;
 }
开发者ID:rszabo,项目名称:egalite,代码行数:38,代码来源:Text.php


示例7: 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


示例8: text

function text($image, $text)
{
    //create resource from image page
    $image = imagecreatefromjpeg($image);
    $font = __DIR__ . '/fonts/Roboto-Light.ttf';
    //leftmost side of image
    $leftX = 0;
    //width of image
    $rightX = imagesx($image);
    //half the height of the image
    $leftY = imagesy($image) / 2;
    //high with padding added for text height, scaled
    $rightY = $leftY - 0.04 * imagesy($image);
    //create rgb(0, 0, 0) with 0.75 alpha for opacity for box background
    $black = imagecolorallocatealpha($image, 0, 0, 0, 75);
    //create rgb(255, 255, 255) for text color
    $whiteText = imagecolorallocate($image, 255, 255, 255);
    //add rectangle
    imagefilledrectangle($image, $leftX, $leftY, $rightX, $rightY, $black);
    //get bounding box for text
    $boundingBox = imagettfbbox(0.03 * imagesy($image), 0, $font, $text);
    //calculate leftmost x position for text placement to be in center
    $x = ($rightX - ($boundingBox[0] + $boundingBox[2])) / 2;
    //add text to image in box
    imagettftext($image, 0.03 * imagesy($image), 0, $x, $leftY - $leftY * 0.015, $whiteText, $font, $text);
    //save new image with text as jpeg
    imagejpeg($image, __DIR__ . "/cache/image.jpg");
    //get image data
    $fileData = file_get_contents(__DIR__ . "/cache/image.jpg");
    //remove image from memory and remove from disk
    imagedestroy($image);
    unlink(__DIR__ . '/cache/image.jpg');
    //return jpeg data
    return $fileData;
}
开发者ID:nodir-y,项目名称:SC-API,代码行数:35,代码来源:func.php


示例9: genImage

function genImage($width, $height, $fontsize, $font_path, $bg_color_str, $txt_color_str)
{
    header("Content-Type: image/png");
    // Create a new image resource
    $img = imagecreatetruecolor($width, $height);
    $bgColorArry = getRGB($bg_color_str);
    $txtColorArry = getRGB($txt_color_str);
    // Set default color values if the passed background- or textcolor is invalid.
    if (!$txtColorArry) {
        $txtColorArry = array("r" => 150, "g" => 150, "b" => 150);
    }
    if (!$bgColorArry) {
        $bgColorArry = array("r" => 204, "g" => 204, "b" => 204);
    }
    // define the color of the background and text color
    $bg_color = imagecolorallocate($img, $bgColorArry["r"], $bgColorArry["g"], $bgColorArry["b"]);
    $txt_color = imagecolorallocate($img, $txtColorArry["r"], $txtColorArry["g"], $txtColorArry["b"]);
    // fill the image with the background color
    imagefill($img, 0, 0, $bg_color);
    // The actual text to be written. E.g. "1280x720"
    $image_text = $width . "x" . $height;
    // calculate the x and y coordinate of the text so that it renders it at the center of the image.
    $bbox = imagettfbbox($fontsize, 0, $font_path, $image_text);
    $text_x = $bbox[0] + imagesx($img) / 2 - $bbox[4] / 2;
    $text_y = $bbox[1] + imagesy($img) / 2 - $bbox[5] / 2;
    // draw the text at the calculated x and y value with the desired color
    imagettftext($img, $fontsize, 0, $text_x, $text_y, $txt_color, $font_path, $image_text);
    // output the image to the browser.
    imagepng($img);
    // free the used resources
    imagedestroy($img);
}
开发者ID:Daxda,项目名称:image-placeholder-generator,代码行数:32,代码来源:gen.php


示例10: MediabirdCaptchaImages

 /**
  * Generates a Mediabird captcha image and reads it back to the client
  * @param int $width Width of image
  * @param int $height Height of image
  * @param int $characters Amount of characters to present
  */
 function MediabirdCaptchaImages($width = '120', $height = '40', $characters = '5')
 {
     $code = $this->generateCode($characters);
     /* font size will be 75% of the image height */
     $font_size = $height * 0.65;
     $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $background_color = imagecolorallocate($image, 228, 228, 228);
     $text_color = imagecolorallocate($image, 96, 88, 143);
     $noise_color = imagecolorallocate($image, 154, 150, 180);
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     /* generate random lines in background */
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     /* create textbox and add text */
     $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2 - 3;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
     /* output captcha image to browser */
     header('Content-Type: image/png');
     imagepng($image);
     imagedestroy($image);
     $this->code = $code;
 }
开发者ID:hmatulis,项目名称:RTL-BIDI-Hebrew-Moodle-Plugins,代码行数:35,代码来源:captcha.php


示例11: showImage

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


示例12: captcha

function captcha($mot)
{
    $size = 64;
    $marge = 15;
    $font = '../fonts/angelina.ttf';
    $matrix_blur = array(array(1, 1, 1), array(1, 1, 1), array(1, 1, 1));
    $box = imagettfbbox($size, 0, $font, $mot);
    $largeur = $box[2] - $box[0];
    $hauteur = $box[1] - $box[7];
    $largeur_lettre = round($largeur / strlen($mot));
    $img = imagecreate($largeur + $marge, $hauteur + $marge);
    $blanc = imagecolorallocate($img, 255, 255, 255);
    $noir = imagecolorallocate($img, 0, 0, 0);
    $couleur = array(imagecolorallocate($img, 0x99, 0x0, 0x66), imagecolorallocate($img, 0xcc, 0x0, 0x0), imagecolorallocate($img, 0x0, 0x0, 0xcc), imagecolorallocate($img, 0x0, 0x0, 0xcc), imagecolorallocate($img, 0xbb, 0x88, 0x77));
    for ($i = 0; $i < strlen($mot); ++$i) {
        $l = $mot[$i];
        $angle = mt_rand(-35, 35);
        imagettftext($img, mt_rand($size - 7, $size), $angle, $i * $largeur_lettre + $marge, $hauteur + mt_rand(0, $marge / 2), $couleur[array_rand($couleur)], $font, $l);
    }
    imageline($img, 2, mt_rand(2, $hauteur), $largeur + $marge, mt_rand(2, $hauteur), $noir);
    imageline($img, 2, mt_rand(2, $hauteur), $largeur + $marge, mt_rand(2, $hauteur), $noir);
    imageconvolution($img, $matrix_blur, 10, 10);
    imageconvolution($img, $matrix_blur, 10, 0);
    imagepng($img);
    imagedestroy($img);
}
开发者ID:ChristopheSio,项目名称:GSB,代码行数:26,代码来源:captcha.php


示例13: meme_text

function meme_text($img, $text, $position, $lcrpos, $updown)
{
    global $ppath, $fontsize, $fontstrike, $fontfile, $offset;
    $font = $ppath . $fontfile;
    $bbox = imagettfbbox($fontsize, 0, $font, $text);
    $imgw = imagesx($img);
    $imgh = imagesy($img);
    $x = $bbox[0] + imagesx($img) / 2 - $bbox[4] / 2 - 100;
    $y = $bbox[1] + imagesy($img) / 2 - $bbox[5] / 2 - 5;
    $fw = abs($bbox[2] - $bbox[0]);
    $fh = abs($bbox[7] - $bbox[1]);
    $centerx = ($imgw - $fw) / 2;
    $centery = ($imgh + $fh) / 2;
    if ($lcrpos === 1) {
        $xx = $offset;
    } elseif ($lcrpos === 2) {
        $xx = $centerx;
    } elseif ($lcrpos === 3) {
        $xx = $imgw - $fw - $offset;
    }
    $yy = $position * ($fontsize + 2 * $fontstrike);
    $yy = $yy + (int) $updown * 3;
    /*switch( $position )
    	{
    		case 'top' : $yy = 20;break;
    		case 'bottom' : $yy = $imgh - $fh - 20;break;
    	}*/
    $positionx = $xx;
    $positiony = +$fh + +$yy;
    $col = imagecolorallocate($img, 250, 250, 250);
    $strokecol = imagecolorallocate($img, 25, 25, 25);
    imagettfstroketext($img, $fontsize, 0, $positionx, $positiony, $col, $strokecol, $font, $text, $fontstrike);
}
开发者ID:maesson,项目名称:lyft,代码行数:33,代码来源:meme-text.php


示例14: text

	/**
	 * ImageResizeFilter::text()
	 * Фильтр - накладывает полупрозрачный текст по диагонали.
	 * 
	 * @param mixed $arrParams
	 * @return void
	 */
	private static function text($arrParams) {

		$objImg = imagecreatefromjpeg(self::$strFile);	
		
	    //получаем ширину и высоту исходного изображения
	    $intWidth = imagesx($objImg);
	    $intHeight = imagesy($objImg);
	    
	    //угол поворота текста
	    $intAngle =  -rad2deg(atan2((-$intHeight),($intWidth))); 

	    //добавляем пробелы к строке
	    $strText = ' '.$arrParams['text'].' ';
	 
	    $intColor = imagecolorallocatealpha($objImg, $arrParams['red'], $arrParams['green'], $arrParams['blue'], $arrParams['alpha']);
	    
	    $intSize = (($intWidth + $intHeight) / 2) * 2 / strlen($strText);
	    $arrBox  = imagettfbbox($intSize, $intAngle, $arrParams['font'], $strText);
	    $intX = $intWidth / 2 - abs($arrBox[4] - $arrBox[0]) / 2;
	    $intY = $intHeight / 2 + abs($arrBox[5] - $arrBox[1]) / 2;
	 
	    //записываем строку на изображение
	    imagettftext($objImg, $intSize ,$intAngle, $intX, $intY, $intColor, $arrParams['font'], $strText);
	    
	    imagejpeg($objImg, self::$strFile, 100);
	    
	    imagedestroy($objImg);
		
	}//\\ text
开发者ID:ASDAFF,项目名称:Bitrix.include.library,代码行数:36,代码来源:image_resize_filter.php


示例15: CaptchaSecurityImages

 function CaptchaSecurityImages($width = '80', $height = '40', $characters = '6')
 {
     $code = $this->generateCode($characters);
     $font_size = $height * 0.5;
     // font size ที่จะโชว์ใน Captcha
     $image = imagecreatetruecolor($width, $height) or die('Cannot initialize new GD image stream');
     $background_color = imagecolorallocate($image, 255, 255, 255);
     // กำหนดสีในส่วนต่่างๆ
     $text_color = imagecolorallocatealpha($image, 90, 90, 90, 0);
     $noise_color = imagecolorallocate($image, 180, 180, 180);
     imagefilledrectangle($image, 0, 0, 150, 40, $background_color);
     for ($i = 0; $i < $width * $height / 3; $i++) {
         // สุ่มจุดภาพพื้นหลัง
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     for ($i = 0; $i < $width * $height / 150; $i++) {
         // สุ่มเ้ส้นภาพพื้นหลัง
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     /* สร้าง Text box และเพิ่ม Text */
     $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
     /* display captcha image ไปที่ browser */
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
     $_SESSION['security_code'] = $code;
 }
开发者ID:golfcrseven,项目名称:scsuper,代码行数:30,代码来源:captcha.php


示例16: CaptchaSecurityImages

 function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6')
 {
     $code = $this->generateCode($characters);
     /* font size will be 75% of the image height */
     $font_size = $height * 0.75;
     $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $background_color = imagecolorallocate($image, 255, 255, 255);
     $text_color = imagecolorallocate($image, 0, 0, 0);
     $noise_color = imagecolorallocate($image, 226, 82, 207);
     $noise_color1 = imagecolorallocate($image, 64, 179, 255);
     $noise_color2 = imagecolorallocate($image, 255, 204, 190);
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 250; $i++) {
         imageellipse($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color2);
     }
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imagedashedline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color1);
     }
     /* generate random lines in background */
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imagedashedline($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 */
     imagejpeg($image);
     imagedestroy($image);
     $_SESSION['security_code'] = $code;
 }
开发者ID:Coding110,项目名称:cbvideo,代码行数:34,代码来源:captcha_simple.img.php


示例17: CaptchaSecurityImages

 function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6')
 {
     $code = $this->generateCode($characters);
     /* font size will be 75% of the image height */
     // changed to .55 to Adler
     $font_size = $height * 0.55;
     $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, mt_rand(150, 155), mt_rand(190, 200), mt_rand(248, 252));
     //
     $noise_color = imagecolorallocate($image, mt_rand(235, 239), mt_rand(242, 246), mt_rand(249, 252));
     //
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 3; $i++) {
         $x1 = mt_rand(0, $width);
         $y1 = mt_rand(0, $height);
         imagefilledrectangle($image, $x1, $y1, $x1, $y1, $noise_color);
     }
     /* generate random lines in background */
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     /* create textbox and add text */
     $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2.3;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
     /* output captcha image to browser */
     imagejpeg($image);
     imagedestroy($image);
     $_SESSION['security_code'] = $code;
 }
开发者ID:pzingg,项目名称:saugus_elgg,代码行数:34,代码来源:csi.php


示例18: center_text

function center_text($string, $font_size)
{
    global $fontname;
    $image_width = 800;
    $dimensions = imagettfbbox($font_size, 0, $fontname, $string);
    return ceil(($image_width - $dimensions[4]) / 2);
}
开发者ID:kleitz,项目名称:Text-to-Image,代码行数:7,代码来源:index.php


示例19: textFormat

 /**
  * Форматирует текст (согласно текущему установленному шрифту), 
  * что бы он не вылезал за рамки ($bWidth, $bHeight)
  * Убирает слишком длинные слова
  */
 public function textFormat($bWidth, $bHeight, $text)
 {
     // Если в строке есть длинные слова, разбиваем их на более короткие
     // Разбиваем текст по строкам
     $strings = explode("\n", preg_replace('!([^\\s]{24})[^\\s]!su', '\\1 ', str_replace(array("\r", "\t"), array("\n", ' '), $text)));
     $textOut = array(0 => '');
     $i = 0;
     foreach ($strings as $str) {
         // Уничтожаем совокупности пробелов, разбиваем по словам
         $words = array_filter(explode(' ', $str));
         foreach ($words as $word) {
             // Какие параметры у текста в строке?
             $sizes = imagettfbbox($this->ttfFontSize, 0, $this->ttfFont, $textOut[$i] . $word . ' ');
             // Если размер линии превышает заданный, принудительно
             // перескакиваем на следующую строку
             // Иначе пишем на этой же строке
             if ($sizes[2] > $bWidth) {
                 $textOut[++$i] = $word . ' ';
             } else {
                 $textOut[$i] .= $word . ' ';
             }
             // Если вышли за границы текста по вертикали, то заканчиваем
             if ($i * $this->ttfFontSize >= $bHeight) {
                 break 2;
             }
         }
         // "Естественный" переход на новую строку
         $textOut[++$i] = '';
         if ($i * $this->ttfFontSize >= $bHeight) {
             break;
         }
     }
     return implode("\n", $textOut);
 }
开发者ID:Vladimir3261,项目名称:microFramework,代码行数:39,代码来源:TtfText.php


示例20: Captcha

 public function Captcha($width = '90', $height = '40', $characters = '4')
 {
     $fontLocation = sfConfig::get('sf_symfony_lib_dir') . "/data/font/monofont.ttf";
     $code = $this->generateCode($characters);
     $font_size = $height * 0.85;
     $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     $background_color = imagecolorallocate($image, 255, 255, 255);
     $text_color = imagecolorallocate($image, 80, 90, 140);
     $noise_color = imagecolorallocate($image, 110, 130, 170);
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     $textbox = imagettfbbox($font_size, 0, $fontLocation, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $fontLocation, $code) or die('Error in imagettftext function');
     sfContext::getInstance()->getUser()->setAttribute('captcha_code', $code);
     header('Content-Type: image/jpeg');
     header('Cache-Control: no-cache, must-revalidate');
     imagejpeg($image);
     imagedestroy($image);
 }
开发者ID:kotow,项目名称:work,代码行数:25,代码来源:CaptchHelper.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP imagettftext函数代码示例发布时间:2022-05-15
下一篇:
PHP imagetruecolortopalette函数代码示例发布时间: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