<?php
//使用php生成图片缩略图
// 1.得到原图大小
$filename = './images/img1.jpeg';
// 创建图片画布
$src_img = imagecreatefromjpeg($filename);//原图
$src_width = imagesx($src_img); //原图宽
$src_height = imagesy($src_img); //原图高
//定义缩略百分比
$percent = 0.5;
$new_width = $src_width * $percent; //新图片的宽
$new_height = $src_height * $percent; //新图片的高
// 创建图片画布
$new_img = imagecreatetruecolor($new_width,$new_height);
// 生成缩略图(重新采集)imagecopyresampled — 重采样拷贝部分图像并调整大小
imagecopyresampled($new_img, $src_img, 0, 0, 0, 0, $new_width, $new_height, $src_width, $src_height);
//保存图片
imagejpeg($new_img,'./images/sma_img1.jpeg',100);
//释放资源
imagedestroy($new_img);
imagedestroy($src_img);