- 在线时间
- 7676 小时
- 专家
- 0
- UID
- 207382
- 注册时间
- 2005-9-17
- 帖子
- 15893
- 精华
- 0
- 积分
- 20278
- 居住地
- 北京市 海淀区
- 离线
- 0 天
专长: PHP,MySQL,项目管理
- 帖子
- 15893
- 体力
- 19481
- 威望
- 19
- 居住地
- 北京市 海淀区
|
我用GD函数生成缩略图没有内存占用严重的情况
- <?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');
- ?>
复制代码 |
|