/*
* title :resizeThumbnailImage 压缩图片
* param :$thumb 压缩后的路径 绝对
* param :$p_w_picpath 压缩前的路径 绝对
* param :$scale 压缩比率 0.5 = 50%
* param :$fixed array('width'=>64, 'height'=>64);  压缩后的宽高
* return:string 压缩后的路径
*/
function resizeThumbnailImage($thumb,$p_w_picpath,$scale,$fixed=array()){
list($p_w_picpathwidth, $p_w_picpathheight, $p_w_picpathType) = getp_w_picpathsize($p_w_picpath);
$p_w_picpathType = p_w_picpath_type_to_mime_type($p_w_picpathType);
if(isset($fixed['width']) && isset($fixed['height'])){
$newImageWidth = $p_w_picpathwidth < $fixed['width'] ? $p_w_picpathwidth : $fixed['width'];
$newImageHeight = $p_w_picpathheight < $fixed['height'] ? $p_w_picpathheight : $fixed['height'];
}else{
$newImageWidth = ceil($p_w_picpathwidth * $scale);
$newImageHeight = ceil($p_w_picpathheight * $scale);
}
$newImage = p_w_picpathcreatetruecolor($newImageWidth,$newImageHeight);
switch($p_w_picpathType) {
case "p_w_picpath/gif":
$source=p_w_picpathcreatefromgif($p_w_picpath);
break;
case "p_w_picpath/pjpeg":
case "p_w_picpath/jpeg":
case "p_w_picpath/jpg":
$source=p_w_picpathcreatefromjpeg($p_w_picpath);
break;
case "p_w_picpath/png":
case "p_w_picpath/x-png":
$source=p_w_picpathcreatefrompng($p_w_picpath);
break;
}
p_w_picpathcopyresampled($newImage,$source,0,0,0,0,$newImageWidth,$newImageHeight,$p_w_picpathwidth,$p_w_picpathheight);
switch($p_w_picpathType) {
case "p_w_picpath/gif":
p_w_picpathgif($newImage,$thumb);
break;
case "p_w_picpath/pjpeg":
case "p_w_picpath/jpeg":
case "p_w_picpath/jpg":
p_w_picpathjpeg($newImage,$thumb,100);
break;
case "p_w_picpath/png":
case "p_w_picpath/x-png":
p_w_picpathpng($newImage,$thumb);
break;
}
return $thumb;
}