PHP大图生成缩略图(0 位领导批示)

原贴地址: http://bbs.blueidea.com/thread-2997569-1-1.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?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');
?>

相关文章

分享到新浪微博 推荐到豆瓣 分享到 Google Reader 加入Google书签 嘀咕一下 分享到饭否 分享到做啥 分享到叽歪 分享到鲜果 加入QQ书签 加入百度搜藏 加入雅虎书签 分享到垦一垦

银子曰:还没有领导题词?

请领导指示

验证码 (必须)

Additional comments powered by BackType

随机显示的10篇日志

评论最多的10篇日志

浏览最多的10篇日志