<?php /** * 生成缩略图 * * @param string $imagePath 图片路径 * @param string $thumb 生成缩略图名称 * @param integer $width 生成缩略图最大宽度 * @param integer $height 生成缩略图最大高度 * * @author Silver * @link http://www.zdyi.com */ function resizeImage($imagePath, $thumb, $width = 200, $height = 200) { list($imageWidth, $imageHeight) = getimagesize($imagePath); $imagePath = imagecreatefromjpeg($imagePath); if ($width && ($imageWidth < $imageHeight)) { $width = ($height / $imageHeight) * $imageWidth; } else { $height = ($width / $imageWidth) * $imageHeight; } $image = imagecreatetruecolor($width, $height); imagecopyresampled($image, $imagePath, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight); imagepng($image, $thumb); imagedestroy($image); } resizeImage('test.jpg', 'test_thumb.jpg'); ?>