工程目录下,建立images文件夹,放入图片
![cat.jpeg](https://i-blog.csdnimg.cn/blog_migrate/06d5a64181642f7076ccced7819cfc42.jpeg)
<html>
<head>
<title>使用PHP创建缩略图</title>
</head>
<body>
<span>虾米大王使用PHP创建缩略图</span>
<hr>
<?php
$image = imagecreatefromjpeg('images/cat.jpeg');
$width = imagesx($image);
$height = imagesy($image);
$reduce_width = $width * 0.3;
$reduce_height = $height * 0.3;
$reduce_img = imagecreatetruecolor($reduce_width,$reduce_height);
imagecopyresampled($reduce_img,$image,0,0,0,0
,$reduce_width,$reduce_height,$width,$height);
imagejpeg($reduce_img,"images/cat_reduce.jpeg",100); //保存图片
imagedestroy($reduce_img);
?>
<table>
<tr>
<td>原图:</td>
<td>缩略图:</td>
</tr>
<tr>
<td><img src="images/cat.jpeg"></td>
<td valign="top"><img src="images/cat_reduce.jpeg"></td>
</tr>
</table>
</body>
</html>