當前位置:才華齋>計算機>php語言>

php畫圖例項

php語言 閱讀(3.15W)

本文例項講述了PHP畫圖的.方法。分享給大家供大家參考。具體實現方法如下:

php畫圖例項

  複製程式碼 程式碼如下:<?php

// by MoreWindows

$imgWidth = 600;

$imgHeight = 400;

$img = imagecreatetruecolor($imgWidth, $imgHeight);

imagefill($img, 0, 0, imagecolorallocate($img, 240, 240, 240));//設定底色

$snowflake_size = 30;

$font_file = "c:";

//生成大雪花 其實就是呼叫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);

imagettftext($img, 12, 0, $imgWidth - 50 , $imgHeight - 20, $black_color, $font_file, "PHP畫圖");

imagepng($img);

imagedestroy($img);

?>

  本例項執行效果如下圖所示

php畫圖例項1

更多請參考:

希望本文所述對大家的PHP程式設計有所幫助。</p