时间:2021-07-01 10:21:17 帮助过:18人阅读
/** * _thumb()生成缩略图的函数 */ function _thumb($_filename,$_max_size){ //(图片源地址,最大宽or高) //获取文件后缀 $_n = explode('.', $_filename); //生成png表头文件 header('Content-type:image/png'); //获取文件的长和高 list($_width,$_height) = getimagesize($_filename); //生成微缩的长和高 $_percent = $_max_size / (($_width > $_height) ? $_width:$_height); $_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); }
以上就介绍了PHP生成图片缩略图,并在浏览器中显示,灵活,实用,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。