background image

$oheight

 = ImageSY(

$orgImg

);

$tW

 = 

$picInfo

['width'];

$tH

 = 

$picInfo

['height'];

//获取缩略图尺寸
if

(

$owidth

/

$oheight

 > 

$tW

/

$tH

){

$tH

 = 

intval

(

$tW

 * 

$oheight

/

$owidth

);

}

else

{

$tW

 = 

intval

(

$tH

 * 

$owidth

/

$oheight

);

}

//生成背景图

$new_img

 = ImageCreateTrueColor(

$picInfo

['width'], 

$picInfo

['height']);

$bgColor

 = imagecolorallocate(

$new_img

,255,255,255);

if

 (!@imagefilledrectangle(

$new_img

, 0, 0, 

$picInfo

['width']-1, 

$picInfo

['height']-1, 

$bgColor

)) {

echo

 "无法创建背景图"; 

//@todo 记录日志

exit

(0);

}

if

 (!@imagecopyresampled(

$new_img

$orgImg

, (

$picInfo

['width']-

$tW

)/2, (

$picInfo

['height']-

$tH

)/2, 0, 0, 

$tW

$tH

$owidth

$oheight

)) {

echo

 "生成图片失败";

exit

(0);

}

//生成图片

ob_start();
imagejpeg(

$new_img

);

$_newImg

 = ob_get_contents();

ob_end_clean();

file_put_contents

(

$imagePath

.

$picInfo

['name']."/".

$imgName

$_newImg

);

header("Content-type:image/jpeg; charset=utf-8");
imagejpeg(

$new_img

);

?>