background image

 {
     //原图长宽比小于缩略图长宽比,则按照高度优先
     $per=$h/$height;
 }
 $temp_w = intval($width*$per);//计算原图缩放后的宽度
 $temp_h = intval($height*$per);//计算原图缩放后的高度
 $dst_im = imagecreatetruecolor($temp_w, $temp_h);
 //调整大小
 imagecopyresized($dst_im, $im, 0, 0, 0, 0, $temp_w, $temp_h, $width, $height);
 //输出缩小后的图像
 //exit($newfile);
 imagejpeg($dst_im,$dir.'/'.$newfile);
 imagedestroy($dst_im);
 imagedestroy($im);
}
?>

注意:
imagejpeg()函数,前面未加后面的保存路径,一直不成功!
经测试才明白是需要添加一个保存路径!