// 处理宽度和高度
$w = floor ($w / 4);
$h = floor ($h / 4);
$fontContent = 'test font';
$text = iconv("gbk","utf-8", $fontContent);
$box = imagecreatetruecolor($w, $h); // 建立一个画板
$bg = imagecolorallocatealpha($box, 77, 77, 77, 127); // 拾取一个完全透明的颜色
$fgcolor = imagecolorallocate($box, 0, 0, 0); // 字体拾色
imagealphablending($box, false); // 关闭混合模式
imagefill($box, 0, 0, $bg);
//imagefttext($box, 12, 0, 10, 20, $fgcolor, 'msyh.ttf', $text);
imagestring($box, 12, 0, 10, $text, $fgcolor);
imagesavealpha($box , true); // 设置保存PNG时保留透明通道信息
header("Content-type:image/png");
$outFilePath = '.' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . time() .'.png';
imagepng($box, $outFilePath);
imagedestroy($box);
分享到:
>> 下一篇:PHP裁剪BMP图片 (2016-09-19 00:07)