zoukankan      html  css  js  c++  java
  • php生成雪花图像(不美观请见谅)

    <?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);  
     
    ?>
  • 相关阅读:
    iframe,table,window.open求救问题
    你的明星臉~~哈哈~~~(要附正面照片哦==)
    DataGrid的表頭排序問題(GridView雷同了啦)
    致歉(TO师傅)
    程式設計師的著裝(哈哈哈~~~)
    SQL(top与group by)求助
    MySql与超级终端
    hdu 1061 Rightmost Digit
    hdu 2669 Romantic
    poj 1061 青蛙的约会
  • 原文地址:https://www.cnblogs.com/shuangzikun/p/taotao_php_functionsnow.html
Copyright © 2011-2022 走看看