PHP代码
01.<?php
02.// The file
03.$filename = 'mm.jpg';
04.$dstFile="icons/";
05.$filePath="icons/test.jpg";
06.
07.// Set a maximum height and width
08.$width = 100;
09.$height = 100;
10.
11.// Content type
12.header('Content-type: image/jpeg');
13.
14.// Get new dimensions
15.list($width_orig, $height_orig) = getimagesize($filename);
16.
17.if ($width && ($width_orig < $height_orig)) {
18. $width = ($height / $height_orig) * $width_orig;
19.} else {
20. $height = ($width / $width_orig) * $height_orig;
21.}
22.
23.// Resample
24.$image_p = imagecreatetruecolor($width, $height);
25.$image = imagecreatefromjpeg($filename);
26.imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
27.
28.// Output
29.imagejpeg($image_p,$filePath);
30.?>
$filename图片的名称,包括路径
$dstFile目标路径