画像にTrueTypeフォントにてテキストを追加
imagettftext
描画エリアにTrueType形式のフォントテキストを描画
サンプル
<?php
// 200×200の画像リソースを作成
$im = imagecreate(200, 200);
// 白色を作成
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
// 黒色を作成
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
$yellow = imagecolorallocate($im, 0xFF, 0xFF, 0x00);
// 短形を描画する
imagefilledrectangle($im, 50, 50, 150, 150, $yellow);
// フォントを指定
$font = "C:/Windows/Fonts/msgothic.ttc";
// テキストを描画
imagettftext($im, 14, 0, 20, 160, $black, $font, "ほげほげ");
imagettftext($im, 14, 330, 20, 20, $black, $font, "テスト");
imagettftext($im, 14, 90, 120, 160, $black, $font, "1234567");
// 画像出力
header("Content-type: image/png");
ImagePNG($im);
?>
イメージ
最終更新:2012年08月18日 21:55