/*
函数:生成缩略图
MakeBuild("images/a.jpg","news/b.jpg","100");
参数:
echo $BuildFile; 原图 带路径
echo $newFile; 生成的缩略图 带路径
echo $File_width; 缩略图宽度值
echo $File_height; 缩略图高度值 (默认为宽度的比例值)
echo $rate; 缩略图象品质;
*/
function MakeBuild($BuildFile,$newFile,$File_width,$File_height=0,$rate=1000) {
if(!is_file($BuildFile)){
$this->msg("文件 ".$BuildFile." 不是一个有效的图形文件!nn系统无法生成该文件的缩略图!");
return false;
}
$data = GetImageSize($BuildFile);
switch($data[2]){
case 1:
$im = @ImageCreateFromGIF($BuildFile);
break;
case 2:
$im = @ImageCreateFromJPEG($BuildFile);
break;
case 3:
$im = @ImageCreateFromPNG($BuildFile);
break;
}
if(!$im){
return false;
}
else{
$srcW = ImageSX($im); # 取得原图宽度;
$srcH = ImageSY($im); # 取得原图高度;
$dstX = 0;
$dstY = 0;
if($File_height==0){
$File_height = $File_width/$srcW*$srcH;
}
if ($srcW*$File_height>$srcH*$File_width){
$fFile_height = round($srcH*$File_width/$srcW);
$dstY = floor(($File_height-$fFile_height)/2);
$fFile_width = $File_width;
}
else {
$fFile_width = round($srcW*$File_height/$srcH);
$dstX = floor(($File_width-$fFile_width)/2);
$fFile_height = $File_height;
}
$ni = ImageCreateTrueColor($File_width,$File_height);
$dstX = ($dstX<0)?0:$dstX;
$dstY = ($dstX<0)?0:$dstY;
$dstX = ($dstX>($File_width/2))?floor($File_width/2):$dstX;
$dstY = ($dstY>($File_height/2))?floor($File_height/s):$dstY;
ImageCopyResized($ni,$im,$dstX,$dstY,0,0,$fFile_width,$fFile_height,$srcW,$srcH);
ImageJpeg($ni,$newFile,$rate); # 生成缩略图;
imagedestroy($im); # imagedestroy(resource) 释放image关联的内存
}
}
$srcimage = $_GET['image'];
$srcimgurl = "./live/data/attachment/forum/".$image;
$srcimgurl = "./live/data/attachment/forum/201207/30/105704r7zmqhmsltqpqxwh.jpg";
$srcimgs = explode("/",$image);
$srcimg = $srcimgs[count($srcimgs)-1];
$srcimg2 = explode(".",$srcimg);
$newimg = $srcimg2[0]."_slt.".$srcimg2[1];
$newimage = str_replace($srcimg,$newimg,$srcimage);
$newimgurl = str_replace($srcimg,$newimg,$filename);
MakeBuild($filename,$newimgurl,"600");
echo "201207/30/105704r7zmqhmsltqpqxwh.jpg";
?>