//存放图片的文件夹在服务器上的绝对地址$imgRootPath="pics/2005/11/";//例外允许连接的网址,注意:自身域名不需要填入,设定为肯定可以连接图片$excludeReferArr=array("www.163.com","163.com");
doJudgeReferer($excludeReferArr);//判断是否$imgRelPath=$_REQUEST['id'];//src参数if(empty($imgRelPath)){
doOutputMsgImg("未指定要查看的图片!");exit;
}$srcSplitArr=explode(".",$imgRelPath);//获得图片后缀名$srcSuffix=$srcSplitArr[count($srcSplitArr)-1];$srcSuffix=strtolower($srcSuffix);$imgAbsPath="$imgRootPath$imgRelPath";//更换复杂地址if(!file_exists($imgAbsPath))
{
doOutputMsgImg("对不起,此图片链接已经失效!");
}elseif($srcSuffix=="gif") {header("Content-type: image/gif");$image=imagecreatefromgif ($imgAbsPath);
imagegif ($image);
imagedestroy ($image);
}elseif($srcSuffix=="jpg") {header("Content-type: image/jpeg");$image=imagecreatefromjpeg ($imgAbsPath);
imagejpeg ($image);
imagedestroy ($image);
}elseif($srcSuffix=="png") {header("Content-type: image/png");$image=imagecreatefrompng ($imgAbsPath);
imagepng ($image);
imagedestroy ($image);
}else{
doOutputMsgImg("图像类型不支持");
}//**************
//相关函数
//*************functiondoJudgeReferer($excludeReferArr) {$referUrl=parse_url($_SERVER["HTTP_REFERER"]);$referHost=$referUrl[host];if($referHost!=""&&$referHost!=$_SERVER["HTTP_HOST"]&&!in_array($referHost,$excludeReferArr))
{
doOutputMsgImg("这是来自".$referUrl[host]."的盗链!");exit;
}
}functiondoMarkImage($inImg,$inMarkStr="Powered by Wreny.com") {$black=imagecolorallocate ($inImg,0,0,0);$imgWidth=imagesx($inImg);$imgHeight=imagesy($inImg);//289-108,86drawTxt($inImg,$inMarkStr,($imgWidth-strlen($inMarkStr)*9),($imgHeight-16),$black);
}functiondoOutputMsgImg($msg,$imgWidth=468,$imgHeight=60,$imgFgColorArr=array(0,0,0),$imgBgColorArr=array(255,255,255)) {$img=imagecreatetruecolor($imgWidth,$imgHeight);//用白色背景加黑色边框画个方框$backColor=imagecolorallocate($img,255,255,255);$borderColor=imagecolorallocate($img,0,0,0);
imagefilledrectangle($img,0,0,$imgWidth-1,$imgHeight-1,$backColor);
imagerectangle($img,0,0,$imgWidth-1,$imgHeight-1,$borderColor);$imgFgColor=imagecolorallocate ($img,$imgFgColorArr[0],$imgFgColorArr[1],$imgFgColorArr[2]);
drawTxt($img,$msg,($imgWidth-strlen($msg)*9)/2,($imgHeight/2-16),$imgFgColor);
doMarkImage($img);header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
}functionisCharVilid($inStr,$inPos) {if(strlen($inStr)
}else{for($iLoop=0,$iCounter=0;$iLoop<=$inPos;$iLoop++){if(substr($inStr,$iLoop,1)<='~') {$iCounter++;
}
}return( ($iCounter%2)==0);
}
}functiondrawTxt($image,$string,$x,$y,$color) {$fp=fopen("chinese.fon","r");//WIN98中,此文件在:c:\windows\command 下if(feof($fp)) {fclose($fp);return0;
}//GBK$strings=preg_split('/((?:[\\x80-\\xFF][\\x40-\\xFF])+)/',$string,-1,PREG_SPLIT_DELIM_CAPTURE
);//print_r($strings);$isch=false;for($p=0,$count=count($strings);$p0;$xbit>>=1,$xpos++) {if($bits&$xbit) {
imagesetpixel($image,$xpos,$ypos,$color);
}
}
}$x+=16;
}
}else{
imagestring($image,12,$x,$y,$strings[$p],$color);$x+=strlen($strings[$p])*9;
}$isch=!$isch;
}return0;
}?>