分享

php创建图像

 每天学一点7 2013-12-11
 
效果图:
代码:
<?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,$font_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);  
?>  
 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多