ホームページ  >  記事  >  バックエンド開発  >  テキスト png 画像を生成する PHP コード_PHP チュートリアル

テキスト png 画像を生成する PHP コード_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-21 15:30:38948ブラウズ

コードをコピーします コードは次のとおりです:

/*
php はテキスト PNG 画像を生成します。次のメソッドを使用して関数を呼び出すことができます:
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'; // スクリプトが保存されているディレクトリへの相対パス
var $size = 0; / 回転角度
var $pad = 0 ; // パディング。
var $red = 0;
var $blu = 0;
var $ bg_red = 255;
var $bg_blu = 255;
$width = 0; height = 0;
$offset_y = 0;
$bounds = "";
$bounds = ImageTTFBBox;サイズ, $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]);
$font_height = abs($ bounds[7]-$bounds[1]) ;
}
// 境界線の高さを決定します
$bounds = ImageTTFBBox($this->size, $this->font, $ this->msg);
if ($this ->rot $width = abs($bounds[4]-$bounds[0]);
$height = abs($bounds[3]) ]-$bounds[7]);
$offset_y = $font_height;
} 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]);
$width = abs($bounds[4]-$bounds[6]);
$height = abs($bounds[7]) ]-$bounds[1]);
$offset_y = $font_height;;
}
$image = imagecreate($width+($this->pad*2)+1,$height+($ this->pad*2)+1);
$background = ImageColorAllocate($image, $this->bg_grn, $this->bg_blu); image, $this->red, $this->gt;grn, $this->blu);
if ($this->transparent) ImageColorTransparent($image, $background); );
// 描画
ImageTTFText($image , $this->size, $this->rot, $offset_x+$this->pad, $foreground, $this ->font, $this->msg) ;
// png 形式で出力します。
}
}
$text = new textPNG; ->msg = $msg; // 表示する必要があるテキスト
if (isset($font)) $text->font = $font; // フォント
if (isset($size)) $text-> ;size = $size; // 文字サイズ
if ( isset($rot)) $text->rot = $rot; // 回転角度
if (isset($pad)) $text->pad = $ Pad; // パディング
if (isset($red) ) $text->red = $red; // テキストの色
if (isset($grn)) $text->grn = $grn; .
if (isset($blu)) $text- >blu = $blu; // ..
if (isset($bg_red)) $text->bg_red = $bg_red; // 背景色。 (isset($bg_grn)) $text->bg_grn = $bg_grn; // ..
if (isset($bg_blu)) $text->bg_blu = $bg_blu; // ..
if ($ tr)) $text->transparent = $tr; // 透明度 (ブール値)

;



http://www.bkjia.com/PHPjc/323166.html

www.bkjia.com

tru​​e

http://www.bkjia.com/PHPjc/323166.html

技術記事

次のようにコードをコピーします: ? /* php はテキスト PNG イメージを生成します。次のように関数を呼び出すことができます: http://www.yourdomian.com/text_png.php3?msg=helloworld+classsize=48 class textPNG {...





声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。