本文整理汇总了PHP中imagettfbbox函数的典型用法代码示例。如果您正苦于以下问题:PHP imagettfbbox函数的具体用法?PHP imagettfbbox怎么用?PHP imagettfbbox使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagettfbbox函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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
示例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;
}