function thumb($sourceImgPath,$wid="230",$hei="230") {
$rootPath = dirname(dirname(__FILE__));
$newPath = $rootPath.$sourceImgPath;
$sourceImgInfo=getimagesize($newPath);
$s_w=$sourceImgInfo[0];//原图宽
$s_h=$sourceImgInfo[1];//原图高
switch ($sourceImgInfo[2]){
case 1:
$S_img=imagecreatefromgif($newPath);
break;
case 2:
$S_img=imagecreatefromjpeg($newPath);
break;
case 3:
$S_img= imagecreatefrompng($newPath);
break;
}
$t_img=imagecreatetruecolor($wid, $hei);
$bgcolor=imagecolorallocate($t_img, 255, 255, 255);
imagefill($t_img, 0, 0,$bgcolor);
$z_w=$wid/$s_w;
$z_h=$hei/$s_h;
$zoom=min($z_w,$z_h);
$new_w=$zoom*$s_w;
$new_h=$zoom*$s_h;
imagecopyresized($t_img, $S_img,($wid-$new_w)/2,($hei-$new_h)/2,0,0,$new_w,$new_h, $s_w, $s_h);
//$t_img缩略图画布
//$s_img:原图
//X1,Y1 缩略图图像开始位置(0,0)
//X2,Y2 原图从什么位置开始取图像(0,0)
//X3,Y3 缩略图图像结束位置($wid,$hei)
//X4,Y4 原图从什么位置结束取图像(s_w,s_h)
//header("content-type:image/png");
$p=explode('.',$newPath);
$ext = array_pop($p);
$newName = MD5(uniqid()).'.'.$ext;
$PathName =$rootPath. '/upload/sincopar/';
if (!is_dir($PathName)) {
if (!mkdir($PathName, 0777, true)) {
$_SESSION['fileerror']= 13;
header('location:../after_end/info.php');
exit();
}
}
$imagepng = imagepng($t_img,$PathName.$newName);
imagedestroy($t_img);
imagedestroy($S_img);
return '/upload/sincopar/'.$newName;
}
$rootPath = dirname(dirname(__FILE__));
$newPath = $rootPath.$sourceImgPath;
$sourceImgInfo=getimagesize($newPath);
$s_w=$sourceImgInfo[0];//原图宽
$s_h=$sourceImgInfo[1];//原图高
switch ($sourceImgInfo[2]){
case 1:
$S_img=imagecreatefromgif($newPath);
break;
case 2:
$S_img=imagecreatefromjpeg($newPath);
break;
case 3:
$S_img= imagecreatefrompng($newPath);
break;
}
$t_img=imagecreatetruecolor($wid, $hei);
$bgcolor=imagecolorallocate($t_img, 255, 255, 255);
imagefill($t_img, 0, 0,$bgcolor);
$z_w=$wid/$s_w;
$z_h=$hei/$s_h;
$zoom=min($z_w,$z_h);
$new_w=$zoom*$s_w;
$new_h=$zoom*$s_h;
imagecopyresized($t_img, $S_img,($wid-$new_w)/2,($hei-$new_h)/2,0,0,$new_w,$new_h, $s_w, $s_h);
//$t_img缩略图画布
//$s_img:原图
//X1,Y1 缩略图图像开始位置(0,0)
//X2,Y2 原图从什么位置开始取图像(0,0)
//X3,Y3 缩略图图像结束位置($wid,$hei)
//X4,Y4 原图从什么位置结束取图像(s_w,s_h)
//header("content-type:image/png");
$p=explode('.',$newPath);
$ext = array_pop($p);
$newName = MD5(uniqid()).'.'.$ext;
$PathName =$rootPath. '/upload/sincopar/';
if (!is_dir($PathName)) {
if (!mkdir($PathName, 0777, true)) {
$_SESSION['fileerror']= 13;
header('location:../after_end/info.php');
exit();
}
}
$imagepng = imagepng($t_img,$PathName.$newName);
imagedestroy($t_img);
imagedestroy($S_img);
return '/upload/sincopar/'.$newName;
}