分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

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

发布时间:2023-09-06 01:33责任编辑:熊小新关键词:暂无标签
<?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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved