php创建图像

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

php创建图像
效果图:
代码:
<?php
$imgWidth = 800;
$imgHeight = 500;
$img = imagecreatetruecolor($imgWidth, $imgHeight);//创建一个空白的背景
$bgcolor = imagecolorallocate($img,240,240,240);//为图像定义背景颜色
imagefill($img, 0, 0, $bgcolor);//为图像绘画背景色
$font_size = 30;//设置字体大小
$font_name = "c:\\WINDOWS\\Fonts\\simhei.ttf";//设置字体样式
//生成大雪花其实就是调用imagettftext()输出*号
for ($i=1; $i<=300; $i++)//生产雪花的数目,最多为300个
{
$font_color = imagecolorallocate($img, mt_rand(100,200), mt_rand(100,200), mt_rand(100,200));//随机生成不同的颜色//将*打印到背景上
//imagettftext()函数语法:imagegettftext($img,$font_size,0,$text_x,$text_y,$font_color,$fo nt_name,$text)
//参数意思依次为:图像标识符,像素表示的字体大小,文本的倾斜角度,文本起始的x,y坐标,文本颜色及字体,写入到背景上的内容
imagettftext($img, $font_size, mt_rand(0, 180), mt_rand(0, $imgWidth),mt_rand(0, $imgHeight), $font_color, $font_name,
"*");
}
//水印文字
$blue_color = imagecolorallocate($img, 0, 0, 64);
imagettftext($img, 12, 0, $imgWidth - 150 , $imgHeight - 20, $blue_color, $font_name, "雪花图--php绘制");
header('content-type:image/png');//指定图像的MIME类型
imagepng($img); //输出图像到浏览器
imagedestroy($img);
>。

相关文档
最新文档