<?php
$width?=?200;
$height?=?50;
$image?=?imagecreatetruecolor($width,$height);
$white?=?imagecolorallocate($image,255,255,255);
$rand_color?=?imagecolorallocate($image,mt_rand(60,125),mt_rand(60,125),mt_rand(60,125));
imagefilledrectangle($image,0,0,$width,$height,$white);
$string?=?join('',array_merge(range(0,9),range('a','z'),range('A','Z')));
$number?=?4;
for($i?=?0;$i?<?$number;$i++){
????$angle?=?mt_rand(-15,15);
????$fontsize?=?mt_rand(24,28);
????$text?=?str_shuffle($string)[0];
????$x?=?20?+?40?*?$i;
????$y?=?35;
????imagettftext($image,$fontsize,$angle,$x,$y,$rand_color,'msyh.ttc',$text);
}
header('content-type:image/png');
imagepng($image);
imagedestroy($image);
?>
2017-04-07
嗯嗯,謝謝樓主
2020-04-03
顯示一片黑的情況可以在header前加一句ob_clean();是用于清除緩沖區(qū)的,我從別的地方看到的,具體原因未知。
2018-05-08
<?php?
$width=400;
$height=50;
$image=imagecreatetruecolor($width,$height);
$white=imagecolorallocate($image,255,255,255);
$randColor=imagecolorallocate($image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagefilledrectangle($image,0,0,$width,$height,$white);
$num = 4;
for($i = 0;$i<$num;$i++){
$size=mt_rand(20,28);
$angle=mt_rand(-15,15);
$x=20 + 40*$i;
$y=30;
$text=mt_rand(1000,9999);
imagettftext($image,$size,$angle,$x,$y,$randColor,'SIMYOU.ttf',$text);
}
header('content-type:image/png');
imagepng($iamge);
imagedestroy($image);
?>?
能幫忙看一下嗎,我的代碼也是顯示不出來
2017-08-24
您幫我看看,這個和你的代碼有什么不一樣嗎?我這個運行出來是一片黑的……