首页 > Web开发 > 详细

php生成雪花图像(不美观请见谅)

时间:2018-01-02 12:27:56      阅读:216      评论:0      收藏:0      [点我收藏+]
<?php
/* 
//新建图像
//雪花
 @header("Content-Type:image/png");
$w = 500;
$h = 500;
//create
$img = imagecreate($w,$h);
//设置底色
imagecolorallocate($img,120,200,150);    
$snowflake_size = 5;  //1dao5
//利用循环生成雪花    imagechar() 输出*号
for ($i=1; $i<=400; $i++){
    imagechar($img,$snowflake_size,mt_rand(0,$w),mt_rand(0,$h),"*",imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)));
 
}
imagepng($img);
$imagedestroy($img);
//resource imagecreatetruecolor($w,$h);
 */
 
 @header("Content-Type:image/png; charset=utf-8");
$imgWidth = 600;  
$imgHeight = 400;  
$img = imagecreatetruecolor($imgWidth, $imgHeight);  
imagefill($img, 0, 0, imagecolorallocate($img, 240, 240, 240));//设置底色  
$snowflake_size = 30;  
$font_file = "c:\\WINDOWS\\Fonts\\simhei.ttf";   
//生成大雪花 其实就是调用imagettftext()输出*号  
for ($i=1; $i<=400; $i++)   
{  
    $font_color = imagecolorallocate($img, mt_rand(100,200), mt_rand(100,200), mt_rand(100,200));  
    imagettftext($img, $snowflake_size, mt_rand(0, 180), mt_rand(0, $imgWidth),mt_rand(0, $imgHeight), $font_color, $font_file, "*");   
}  
//水印文字  
$black_color = imagecolorallocate($img, 0, 0, 0);
$text = iconv("GB2312", "UTF-8", "雪花儿  by MoreWindows"); //将中文字转换为UTF8   
imagettftext($img, 12, 0, $imgWidth - 200 , $imgHeight - 20, $black_color, $font_file, $text);  
imagepng($img);  
imagedestroy($img);  
 
?>

php生成雪花图像(不美观请见谅)

原文:https://www.cnblogs.com/shuangzikun/p/taotao_php_functionsnow.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!