//参数1 文件名 参数2 缩放比例 function _thumb($_filename,$_percent){ ob_clean(); //生成png标头文件 header('Content-type:image/png'); $_n=explode('.', $_filename); //获取文件的信息,宽和高 list($_width,$_height)=getimagesize($_filename); //生成缩略后的大小 $_new_width=$_width*$_percent; $_new_height=$_height*$_percent; //按照新的大小创建微缩画布 $_new_image=imagecreatetruecolor($_new_width, $_new_height); //按照已经有的图片创建一个画布[按照图片类型] switch($_n[1]){ case 'jpg':$_image=imagecreatefromjpeg($_filename); break; case 'png':$_image=imagecreatefrompng($_filename); break; case 'gif':$_image=imagecreatefromgif($_filename); break; } //将原来的图复制到新的图片上 imagecopyresampled($_new_image, $_image, 0, 0, 0, 0, $_new_width, $_new_height, $_width, $_height); //输出图片 imagepng($_new_image); //销毁新资源句柄 imagedestroy($_new_image); //销毁原资源句柄 imagedestroy($_image); }