当前位置:首页 > PHP教程 > php图像处理 > 列表

php大图生成缩略图实现代码

发布:smiling 来源: PHP粉丝网  添加日期:2014-08-19 10:32:37 浏览: 评论:0 
  1. <?php 
  2. /** 
  3. * 生成缩略图 
  4. * 
  5. * @param string $imagepath 图片路径 
  6. * @param string $thumb 生成缩略图名称 
  7. * @param integer $width 生成缩略图最大宽度 
  8. * @param integer $height 生成缩略图最大高度 
  9. * 
  10.  
  11. */ 
  12. function resizeimage($imagepath, $thumb, $width = 200, $height = 200) 
  13. { 
  14.     list($imagewidth, $imageheight) = getimagesize($imagepath); 
  15.     $imagepath = imagecreatefromjpeg($imagepath); 
  16.     if ($width && ($imagewidth < $imageheight)) 
  17.     { 
  18.         $width = ($height / $imageheight) * $imagewidth; 
  19.     } 
  20.     else 
  21.     { 
  22.         $height = ($width / $imagewidth) * $imageheight; 
  23.     } 
  24.     $image = imagecreatetruecolor($width, $height); 
  25.     imagecopyresampled($image, $imagepath, 0, 0, 0, 0, $width, $height, $imagewidth, $imageheight); 
  26.     imagepng($image, $thumb); 
  27.     imagedestroy($image); 
  28. }//开源代码phpfensi.com 
  29. resizeimage('test.jpg', 'test_thumb.jpg'); 
  30. ?> 

Tags: php大图 生成缩略图

分享到: