Php生成缩略图

来源:互联网 发布:list数据排序 编辑:程序博客网 时间:2024/06/05 13:22
<?phpheader("Content-type: image/jpeg");//原图文件$file = "images/flower_1.jpg";// 缩略图比例$percent = 0.5;// 缩略图尺寸list($width, $height) = getimagesize($file);$newwidth = $width * $percent;$newheight = $height * $percent;// 加载图像$src_im = @imagecreatefromjpeg($file);$dst_im = imagecreatetruecolor($newwidth, $newheight);// 调整大小imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);//输出缩小后的图像imagejpeg($dst_im);imagedestroy($dst_im);imagedestroy($src_im);?>

来自:http://www.5idev.com/p-php_imagecopy_imagecopyresized.shtml#imagecopy


bool imagecopyresized ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h )

将一幅图像中的一块正方形区域拷贝到另一个图像中。dst_imagesrc_image 分别是目标图像和源图像的标识符。如果源和目标的宽度和高度不同,则会进行相应的图像收缩和拉伸。坐标指的是左上角。本函数可用来在同一幅图内部拷贝(如果dst_imagesrc_image 相同的话)区域,但如果区域交迭的话则结果不可预知。 

bool imagecopy ( resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h )
src_im 图像中坐标从src_xsrc_y开始,宽度为 src_w,高度为src_h 的一部分拷贝到dst_im 图像中坐标为dst_xdst_y 的位置上。 


原创粉丝点击