您的位置:首页 > 编程语言 > PHP开发

利用PHP为大图片生成缩略图代码实现

2010-09-13 13:07 1046 查看
<?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');
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: