PHPは、写真書かれたテキストを達成するために機能します


] = $ fileArr [1]。の$ this - >設定= $ CONFIG。}

























/ **
* PHPは、ラップ達成するために画像の書き込みテキストを達成するために
*の@param $のフォントサイズフォントサイズを
* @paramの$角角
* @paramの$フォントフォントパス
* @paramの$文字列画像上にテキストを書き込む
* @param $文字幅は、画像幅に予め設定された
@paramの$フラグワードは改行包まれていません*
* /
パブリック関数wordWrapの($のfontSize、角度$、$フォント、文字列$、真の旗で$幅、$ =){
$ =コンテンツを" ";
IF(フラグに$){
$言葉=爆発(" "$文字列);
foreachの($キー=> $値AS $語){
.. $ TestStr = $コンテンツ"「$値;
$ TESTBOX = imagettfbbox( fontSizeの$、$角度、フォント$、$ TestStrは);
//文字列は、幅が予め設定されたスプライシングを超えたか否かが判断される
IF(($ TESTBOX [2]> $幅)){
= $コンテンツ"\ N-"。
}
。$値= $コンテンツ"";
}
}他{
//配列文字に記憶された1つの単語列に分割
するために($ I = 0; $ Iはmb_strlenを<($文字列); $ I ++){
私は$文字[] = mb_substr(文字列$、$ ,. 1 );
}
foreachの($ $レターL AS){
$ $ = TestStrコンテンツ"" $ 1; ..
$ TESTBOX = imagettfbbox($のfontSize、角度$、$フォント、$ TestStr);
スプライスの列//決意予め設定された幅を超えて
IF(($ TESTBOX [2]> $幅)&&(コンテンツ== $) "!"){
$ =コンテンツ"\ N-";
}
$の$コンテンツ= L ;.
}
}
リターンコンテンツ$;
}

/ **
*実装書かれた絵
*テキスト@paramの$テキストが書き込まれる
、デフォルトはブラウザに直接出力するかどうか* @paramの$フラグ
* /
パブリック関数のwriteWordsToImg(trueに$テキスト、$ =旗) {
IF(空(の$ this - >設定)){
リターンは、 'コンフィグでなければなりません';
}
//画像サイズ取得
$ img_pathWH = getimagesize(の$ this - >設定[ 'ファイルを']);
//指定されたイメージファイル開く
$ IM = imagecreatefrompng(の$ this - >設定[ 'ファイルを']);
#セット透かしフォント色
$色= imagecolorallocatealpha($イム、 0、0、255、75); //
$ = falseに持ってきた。
IF( "A" stripos($テキスト、)== falseに!){
$ =を持っています;真へ
}
{($を持っている)IF
; $ words_text =( "A"、$テキスト)を爆発
の$ words_text [0] =の$ this - > wordWrapの(の$ this - >設定[ 'サイズ']、この$ - >設定[ '角度'] 、の$ this - >設定[ 'fontfile']、$ words_text [0]、の$ this - >設定[ '幅']); // ハンドルラップ
の$ words_text [1] = $ this-> wordWrapの(の$ this - >設定 [ 'サイズ']、の$ this - >設定[ '角度']、の$ this - >設定[ 'fontfile']、$ Words_text [1]、の$ this - >設定[ '幅']); //ハンドルラップ
$ words_text [2] =の$ this - > wordWrapの(の$ this - >設定[ 'サイズ']、の$ this - >設定[ '角度']、の$ this - >設定[ 'fontfile']、$のwords_text [2] 、の$ this - >設定[ '幅']); //自动换行处理
imagettftext($イム、ます$ this->設定[ 'サイズ']、の$ this - >設定[ '角度']、の$ this - >設定[ 'X']、の$ this - >設定[」 Y ']、$色、の$ this - >設定[' fontfile ']、$のwords_text [0])。
imagettftext($ IM、の$ this - >設定[ 'サイズ']、の$ this - >設定[ '角度']、の$ this - >設定[ 'X']、の$ this - >設定[ 'Y'] + 30 、$色の$ this - >設定[ 'fontfile'] "" $ words_text [1])。
imagettftext($ IM、の$ this - >設定[ 'サイズ']、の$ this - >設定[ '角度']、$ img_pathWH [0] / 2 + 70、$ img_pathWH [1] -80、$色、$この- >設定[ 'fontfile']、$のwords_text [2]);
IF($フラグ){
ヘッダ( "コンテンツタイプ:image / PNG")。
imagepng($イム);
imagedestroy($イム);
}
imagepng($ IM、の$ this - >設定[ 'file_nameに'] .'_ 1 'の$ this - >設定。[' file_ext ']);
imagedestroy($イム);
}
$ words_text =の$ this - > wordWrapの(の$ this - >設定[ 'サイズ']、の$ this - >設定[ '角度']、の$ this - >設定[ 'fontfile']、$テキスト、の$ this - >コンフィグ[「幅」])。//自动换行处理
imagettftext($イム、ます$ this->設定[ 'サイズ']、の$ this - >設定[ '角度']、の$ this - >設定[ 'X']、の$ this - >設定[」 Y ']、$色、の$ this - >設定[' fontfile ']、$のwords_text)。
IF($フラグ){
ヘッダ( "コンテンツタイプ:image / PNG")。
imagepng($イム);
imagedestroy($イム);
}
imagepng($ IM、の$ this - >設定[ 'file_nameに'] .'_ 1 'の$ this - >設定。[' file_ext ']);
imagedestroy($イム);
}
}

$テキスト=「親愛なるカン<BR/>あなたが何かを保持し、それを置くことができれば、それは重量挙げと呼ばれ、あなたが何かを保持することができますが、それを下に置くことはできません場合、それはbuedenベアリングと呼ばれています哀れなほど、人々の大半氏は、彼らが愛にいるとき。重い負担を担う\ nは\ nBeingあなたが嫌いな人に素敵なあなたは偽善的な人だという意味ではありません。それはあなたがそれらへのあなたの嫌悪を許容するのに十分成熟していることを意味します。<br/>されていますカン";

$データ=配列(
'ファイル' => '20171226152410.png'、
'サイズ' => 12、
'角度' => 0、
'fontfile' => './フォント/ ChalkboardSE.ttc'、
'幅' => 270、
'X' => 20、
'Y' => 70
);
//使用
$ wordsOnImgObj =新しいwordsOnImg($データ)。
$ wordsOnImgObj-> writeWordsToImg($テキスト)

おすすめ

転載: www.cnblogs.com/ly570/p/10971086.html