<?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);
?>嗯嗯,谢谢楼主
显示一片黑的情况可以在header前加一句ob_clean();是用于清除缓冲区的,我从别的地方看到的,具体原因未知。
<?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);
?>
能帮忙看一下吗,我的代码也是显示不出来
<?php
$width = 200;
$height = 40;
$img = imagecreatetruecolor($width, $height);
$col = imagecolorallocate($img, mt_rand(200, 255),mt_rand(200, 255),mt_rand(200, 255));
$randCol = imagecolorallocate($img, mt_rand(10, 100), mt_rand(10, 100), mt_rand(10, 100));
$string = join('', array_merge(range(0,9), range('a','z'), range('A','Z')));
imagefilledrectangle($img, 0, 0, $width, $height, $col);
$length = 4;
for($i < 0; $i < $length; $i++){
$size = mt_rand(20, 28);
$angle = mt_rand(-15, 15);
$x = 20+40*$i;
$y = 30;
$fontFile = 'GARTON.TTF';
$text = str_shuffle($string)[0];
imagettftext($img, $size, $angle, $x, $y, $randCol, $fontFile, $text);
}
header('content-type:image/png');
imagepng($img);
imagedestroy($img);
?>您帮我看看,这个和你的代码有什么不一样吗?我这个运行出来是一片黑的……