我的只顯示了圖片,并沒有顯示數(shù)字,自己檢查了三遍并沒有檢查出問題,求解答T_T
<?php
? ? //默認(rèn)輸出背景顏色為黑色
? ? $image = imagecreatetruecolor ( 200 , 50 );//設(shè)定一個圖片的大小并賦值給$image
? ? $bgmcolor=imagecolorallocate($image, 255, 255, 255);//給圖片$image分配顏色像素
? ? imagefill($image, 0, 0, $bgmcolor);//將剛生成的像素色值鋪到資源圖像上
//下面兩行代碼放在for循環(huán)后面會報錯
? ? header('content-type:image/png');//輸出圖片前輸出圖片header信息
? ? imagepng($image);//輸出圖片格式和圖片資源
? ? for ($i=0;$i<4;$i++){
? ? ? ? $fontsize=10;
? ? ? ? $fontcolor=imagecolorallocate($image, rand(0,120),? rand(0,120), rand(0,120));
? ? ? ? $fontcontent=rand(0,9);
? ? ? ? $x = rand($i*200/4)+rand(1,9);
? ? ? ? $y = rand(10,30);
? ? ? ? imagestring($image, $fontsize, $x, $y, $fontcontent, $fontcolor);
? ? }
? ? //end
? ? imagedestroy($image);
? ? //使用數(shù)組庫或資源型類型時,在程序最后用自帶方法或者其他方法將資源銷毀,便于系統(tǒng)的回收
?>
2019-04-12
代碼是順序執(zhí)行的,你這樣寫是面向過程,你在for循環(huán)上邊輸出了圖片,for循環(huán)都沒有執(zhí)行