<?php
require_once("global.php");

if(!$url){
	header("location:$webdb[www_url]/images/default/nopic.jpg");
	exit;
}

$power=0;
if(strstr($wh,':')){	//管理员允许明文
	list($w,$h) = explode(':',$wh);
	if($web_admin && $w && $h){
		$power=1;
	}
}else{	//面向大众只能解密处理
	list($w,$h,$code) = explode(',', mymd5($wh,'DE') );
	if( $w && $h && $code==substr(md5($url),26) ){
		$power=1;
	}
}


$w = intval($w*1.5);
$h = intval($h*1.5);

if($w<10 || $h<10){
	header("location:$url");
	exit;
}




$path = ROOT_PATH.$webdb['updir'];

$filenamepath = get_minpic_path($url)."{$w}-{$h}.jpg";

$filepath=$path.$filenamepath;


if(is_file($filepath)){	//如果图片已经生成过的话，就直接跳转显示
	
	$fileurl = tempdir($filenamepath);
	header("location:$fileurl");
	exit;
}elseif($power<1){
	header("location:$url");
	exit;
}

makepath(dirname($filepath));



$localpic = str_replace($webdb[www_url],ROOT_PATH,$url);

if( is_file($localpic) ){	//本网图片
	gdpic($localpic,$filepath,$w,$h,array('fix'=>1));
}else{	//抓取外网图片
	$ck=0;
	if( @copy($url,$filepath) ){
		$ck=1;
	}elseif($filestr=file_get_contents($url)){
		$ck=1;
		write_file($filepath,$filestr);
	}elseif($filestr=sockOpenUrl($url,'GET','',$url)){
		$ck=1;
		write_file($filepath,$filestr);
	}
	if($ck){
		gdpic($filepath,$filepath,$w,$h,array('fix'=>1));
	}
	//if(count(getimagesize($filepath))<1){	//如果不是图片格式文件的话，就删除掉
	//	unlink($filepath);
	//}
}




if(is_file($filepath)){
	$url = tempdir($filenamepath);
}
header("location:$url");
?>