$towh = $tow/$toh;
$srcwh =
$srcw/$srch;
if($towh <= $srcwh){
$ftow =
$tow;
$ftoh = $ftow*($srch/$srcw);
$fmaxtow = $maxtow;
$fmaxtoh =
$fmaxtow*($srch/$srcw);
} else {
$ftoh =
$toh;
$ftow = $ftoh*($srcw/$srch);
$fmaxtoh = $maxtoh;
$fmaxtow =
$fmaxtoh*($srcw/$srch);
}
if($srcw <= $maxtow
&& $srch <= $maxtoh) {
$make_max =
0;//不处理
}
if($srcw > $tow || $srch > $toh)
{
if(function_exists("imagecreatetruecolor") &&
function_exists("imagecopyresampled") && @$ni =
imagecreatetruecolor($ftow, $ftoh))
{
imagecopyresampled($ni, $im, 0, 0, 0, 0, $ftow,
$ftoh, $srcw,
$srch);
//大图片
if($make_max
&& @$maxni = imagecreatetruecolor($fmaxtow, $fmaxtoh))
{
imagecopyresampled($maxni, $im, 0, 0, 0, 0,
$fmaxtow, $fmaxtoh, $srcw, $srch);
}else if (@$maxni
= imagecreatetruecolor(round($srcw/2),
round($srch/2))){
imagecopyresampled($maxni,
$im, 0, 0, 0, 0, round($srcw/2), round($srch/2), $srcw,
$srch);
}
}
elseif(function_exists("imagecreate") &&
function_exists("imagecopyresized") && @$ni = imagecreate($ftow, $ftoh))
{
imagecopyresized($ni, $im, 0, 0, 0, 0, $ftow,
$ftoh, $srcw,
$srch);
//大图片
if($make_max
&& @$maxni = imagecreate($fmaxtow, $fmaxtoh))
{
imagecopyresized($maxni, $im, 0, 0, 0, 0,
$fmaxtow, $fmaxtoh, $srcw, $srch);
}else if (@$maxni
= imagecreate(round($srcw/2),
round($srch/2))){
imagecopyresized($maxni, $im,
0, 0, 0, 0, round($srcw/2), round($srch/2), $srcw,
$srch);
}
} else
{
return
'';
}
if(function_exists('imagejpeg'))
{
imagejpeg($ni,
$dstfile);
//大图片
if($make_max)
{
imagejpeg($maxni,
$bigfile);
}else{
imagejpeg($maxni,
$bigfile);
}
}
elseif(function_exists('imagepng')) {
imagepng($ni,
$dstfile);
//大图片
if($make_max)
{
imagepng($maxni,
$bigfile);
}else{
imagejpeg($maxni,
$bigfile);
}
}
imagedestroy($ni);
if($make_max)
{
}else{
imagedestroy($maxni);
}
}else{
if(function_exists("imagecreatetruecolor") &&
function_exists("imagecopyresampled") && @$ni =
imagecreatetruecolor($srcw, $srch))
{
imagecopyresampled($ni, $im, 0, 0, 0, 0, $srcw,
$ftoh, $srch,
$srch);
//大图片
$maxni =
imagecreatetruecolor($srch, $srch);
imagecopyresampled($maxni, $im, 0, 0, 0, 0, $srcw, $srch, $srcw,
$srch);
} elseif(function_exists("imagecreate")
&& function_exists("imagecopyresized") && @$ni =
imagecreate($ftow, $ftoh)) {
imagecopyresized($ni,
$im, 0, 0, 0, 0, $srcw, $srch, $srcw,
$srch);
//大图片
$maxni =
imagecreate($fmaxtow, $fmaxtoh);
imagecopyresized($maxni, $im, 0, 0, 0, 0, $srcw, $srch, $srcw,
$srch);
} else
{
return
'';
}
imagejpeg($ni, $dstfile);
imagejpeg($maxni,
$bigfile);
}
imagedestroy($im);
if(!file_exists($dstfile)) {
return
'';
} else {
return
$dstfile;
}
}
#*********************************************************
#获取随机数函数
#*********************************************************
function
yl_createrand($length, $numeric = 0) {
PHP_VERSION < '4.2.0'
&& mt_srand((double)microtime() * 1000000);
if($numeric)
{
$hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10,
$length) - 1));
} else {
$hash =
'';
$chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';///0123456789
$max
= strlen($chars) - 1;
for($i = 0; $i < $length; $i++)
{
$hash .= $chars[mt_rand(0,
$max)];
}
}
return
$hash;
}
#***************
#*********************************************************
#创建目录函数
#*********************************************************
function
createfolder($yl_path)
{
if
(!file_exists($yl_path))
{
$this ->
createfolder(dirname($yl_path));
@mkdir($yl_path,
0777);
}
return $this ->
createfolder;
}
#*********************************************************
#获取文件