Copy CodeThe code is as follows:
/*
PHP generates a text PNG image, which can be called using the following methods:
Http://www.yourdomian.com/text_png.php3?msg=helloworld+class&rot=15&size=48&font=fonts/ARIAL. TTF
*/
Header ("Content-type:image/png");
Class Textpng {
var $font = ' Fonts/times. TTF '; The default font. Relative path to the directory relative to the script.
var $msg = "undefined"; The default text.
var $size = 24;
var $rot = 0; Rotation angle.
var $pad = 0; Fill.
var $transparent = 1; Text transparency.
var $red = 0; In the black background ...
var $grn = 0;
var $blu = 0;
var $bg _red = 255; Sets the text to white.
var $bg _grn = 255;
var $bg _blu = 255;
function Draw () {
$width = 0;
$height = 0;
$offset _x = 0;
$offset _y = 0;
$bounds = Array ();
$image = "";
Determines the text height.
$bounds = Imagettfbbox ($this->size, $this->rot, $this->font, "W");
if ($this->rot < 0) {
$font _height = ABS ($bounds [7]-$bounds [1]);
} else if ($this->rot > 0) {
$font _height = ABS ($bounds [1]-$bounds [7]);
} else {
$font _height = ABS ($bounds [7]-$bounds [1]);
}
Determines the height of the border.
$bounds = Imagettfbbox ($this->size, $this->rot, $this->font, $this->msg);
if ($this->rot < 0) {
$width = ABS ($bounds [4]-$bounds [0]);
$height = ABS ($bounds [3]-$bounds [7]);
$offset _y = $font _height;
$offset _x = 0;
} else if ($this->rot > 0) {
$width = ABS ($bounds [2]-$bounds [6]);
$height = ABS ($bounds [1]-$bounds [5]);
$offset _y = ABS ($bounds [7]-$bounds [5]) + $font _height;
$offset _x = ABS ($bounds [0]-$bounds [6]);
} else {
$width = ABS ($bounds [4]-$bounds [6]);
$height = ABS ($bounds [7]-$bounds [1]);
$offset _y = $font _height;;
$offset _x = 0;
}
$image = imagecreate ($width + ($this->pad*2) +1, $height + ($this->pad*2) +1);
$background = Imagecolorallocate ($image, $this->bg_red, $this->bg_grn, $this->bg_blu);
$foreground = Imagecolorallocate ($image, $this->red, $this->grn, $this->blu);
if ($this->transparent) imagecolortransparent ($image, $background);
Imageinterlace ($image, false);
Drawing.
Imagettftext ($image, $this->size, $this->rot, $offset _x+ $this->pad, $offset _y+ $this->pad, $foreground, $ This->font, $this->msg);
The output is in PNG format.
Imagepng ($image);
}
}
$text = new Textpng;
if (Isset ($msg)) $text->msg = $msg; Text that needs to be displayed
if (Isset ($font)) $text->font = $font; Font
if (Isset ($size)) $text->size = $size; Text Size
if (Isset ($rot)) $text->rot = $rot; Rotation angle
if (Isset ($pad)) $text->pad = $pad; Padding
if (Isset ($red)) $text->red = $red; Text color
if (Isset ($GRN)) $text->grn = $GRN; // ..
if (Isset ($BLU)) $text->blu = $blu; // ..
if (Isset ($BG _red)) $text->bg_red = $BG _red; Background color.
if (Isset ($BG _grn)) $text->bg_grn = $BG _grn; // ..
if (Isset ($BG _blu)) $text->bg_blu = $BG _blu; // ..
if (Isset ($TR)) $text->transparent = $tr; Transparency (Boolean).
$text->draw ();
?>
http://www.bkjia.com/PHPjc/323166.html www.bkjia.com true http://www.bkjia.com/PHPjc/323166.html techarticle Copy the code as follows:?/* PHP generates a text PNG image, you can call the function as follows: http://www.yourdomian.com/text_png.php3?msg=helloworld+classsize=48 Class Textpng {...