源代码如下:function addWaterMark(){
//echo ; $image=upLoad();//upLoad()返回的是图像的名称 if($image){
$img=getimagesize($image);//$img[2]的值意义:1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP
$im=encode($img[2],$image);//encode()函数是将图像编码转换成php可识别的编码方式 $fontcol=imagecolorallocate($im,1,1,1);
$str=iconv("gbk","utf-8","简 * 爱");
imagettftext($im,12,0,100,300,$fontcol,"simhei.ttf",$str);
header("Content-type:image/jpeg");
imagejpeg($im);
}
}
输出结果:
<script>alert('上传成功!')</script>?JFIF>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality
C
$.' ",#(7),01444'9=82<.342C 2!!22222222222222222222222222222222222222222222222222?&"
?}!1AQa"q2亼?#B绷R佯$3br?
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz儎厗噲墛挀敃枟槞殺¥ウЖ┆渤吹斗腹郝媚牌侨墒矣哉本人新手哇、、请高手不吝指教、、先谢了哈
不是按照Content-type:image/jpeg格式输出的
这个我也不太清楚得等高手来解决
感觉你的代码应该是第二页有问题
function upLoad(){
$upFile=$_FILES["upFile"];
$name=$upFile["name"];
$type=$upFile["type"];
$tmp_name=$upFile["tmp_name"];
$error=$upFile["error"];
$size=$upFile["size"]; //判断只能上传指定格式的图片
switch($type)
{
case "image/pjpeg": $img_ok=1;break;
case "image/bmp": $img_ok=1;break;
case "image/gif": $img_ok=1;break;
case "image/png": $img_ok=1;break;
} //将文件移到服务器指定文件夹
if($img_ok){
move_uploaded_file($tmp_name,$name);
echo "<script>alert('上传成功!')</script>";
return $name;
}else{
echo "<script>alert('上传的不是指定类型的图片,上传失败!')</script>";
} //echo $name;
}以上是upload()函数的源代码哈、、、
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
<form name="form1" action="newEmptyPHP.php" method="POST" enctype="multipart/form-data">
<input type="file" name="upFile" value="" />
<input type="submit" value="提交" />
</form> </div>
</body>
</html>newEmptyPHP.php<?php$upFile = $_FILES['upFile'];
$name = $upFile["name"];
$type = $upFile["type"];
$tmp_name = $upFile["tmp_name"];
$error = $upFile["error"];
$size = $upFile["size"];//判断只能上传指定格式的图片
switch ($type) {
case "image/pjpeg": $img_ok = 1;
break;
case "image/bmp": $img_ok = 1;
break;
case "image/gif": $img_ok = 1;
break;
case "image/png": $img_ok = 1;
break;
}//将文件移到服务器指定文件夹
if ($img_ok) {
move_uploaded_file($tmp_name, $name);
echo "<img src=$name />";
} else {
echo "<script>alert('上传的不是指定类型的图片,上传失败!')</script>";
}?>
我这测试成功你看看行不行