@blog.justoneplanet.info

日々勉強

PHPとGDで透過png画像テキストを出力する

透明度のあるイメージをつくる。

<?php
$width  = 300;// px
$height = 40;// px
$text   = 'This is a sample.';// string
$font   = '/usr/share/fonts/bitstream-vera/ACaslonPro-Bold.otf';// path

$img             = imagecreatetruecolor($width, $height);
$color           = imagecolorallocatealpha($img, 210, 0, 0, 255);
$backgroundColor = imagecolorallocatealpha($img, 255, 255, 255, 127);
imagealphablending($img, true); // ブレンドモードを設定する
imagesavealpha($img, true); // 完全なアルファチャネルを保存する

imagefill($img, 0, 0, $backgroundColor); // 指定座標から指定色で塗る
imagettftext($img, 16, 0, 16, 40, $color, $font, $text);

header('Content-type: image/jpeg');
imagepng($img);
imagedestroy($img);
?>

すけすけ画像テキストだ!=3

コメントはまだありません»

コメントはまだありません。

この投稿へのコメントの RSS フィード。TrackBack URL

コメントする