php中生成图片不能生成,全是乱码。

来源:百度知道 编辑:UC知道 时间:2024/05/23 11:32:27
这是我的程序
<?php
$year=date(Y);
$month=date(n);
$week=date(w);
$day=date(j);
$ws=array("1","2","3","4","5","6","7");
$date=$year."年".$month."月".$day."日".$ws[$week];
echo "$date";
$image=imagecreate(80,100);
if($week==5||$week==6){
$colorW=imagecolorallocate($image,225,0,0);
}else{
$colorW=imagecolorallocate($image,0,0,255);
}
//设置日历背景颜色
$colorbk=imagecolorallocate($image,0,0,120);
//设置月份显示颜色,绿色
$colorm=imagecolorallocate($image,0,225,0);
//黑色.显示矩形
$colorb=imagecolorallocate($image,255,255,255);
//白色,日历其余部分
$colorw=imagecolorallocate($image,0,0,0);
//背景色填充日历
imagefill($image,0,0,$colorbk);
//黑色填充一个矩形边框
imagefilledrectangle($image,10,10,70,90,$colorb);
//背景色绘制年
imagestring($image,5,36,15,$year,$colorb);
//绿色显示星期
imagestring($image,5,

少了这一句
header("Content-type: image/gif");

测试过了可以,代码如下,把echo 注释掉
<?php
header("Content-type: image/gif");
$year=date(Y);
$month=date(n);
$week=date(w);
$day=date(j);
$ws=array("1","2","3","4","5","6","7");
$date=$year."年".$month."月".$day."日".$ws[$week];
//echo "$date";
$image=imagecreate(80,100);
if($week==5||$week==6){
$colorW=imagecolorallocate($image,225,0,0);
}else{
$colorW=imagecolorallocate($image,0,0,255);
}
//设置日历背景颜色
$colorbk=imagecolorallocate($image,0,0,120);
//设置月份显示颜色,绿色
$colorm=imagecolorallocate($image,0,225,0);
//黑色.显示矩形
$colorb=imagecolorallocate($image,255,255,255);
//白色,日历其余部分
$colorw=imagecolorallocate($image,0,0,0);
//背景色填充日历
imagefill($image,0,0,$colorbk);
//黑色填充一个矩形边框
imagefilledre