Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1182643
  • 博文数量: 273
  • 博客积分: 6445
  • 博客等级: 准将
  • 技术积分: 2843
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-04 23:22
文章分类

全部博文(273)

文章存档

2024年(2)

2023年(5)

2022年(3)

2021年(18)

2020年(9)

2019年(1)

2018年(13)

2017年(11)

2015年(9)

2013年(2)

2012年(4)

2011年(24)

2010年(114)

2009年(6)

2008年(29)

2007年(13)

2006年(10)

我的朋友

分类:

2010-07-06 10:34:38

function createsmallimg($dir,$source_img,$small_ex="_s") {
$img_name=substr($source_img,0,-4);
$img_ex = strtolower(substr(strrchr($source_img,"."),1));
/*注释的这段用作直接在浏览器上显示图片
$im=imagecreatefromjpeg($file);
header("Content-type: image/jpeg");
imagejpeg($im);*/
switch($img_ex){
   case "jpg":
   $src_img=ImageCreateFromJpeg($dir.$source_img);
   break;
   case "gif":
   $src_img=ImageCreateFromGif($dir.$source_img);
   break;
}
$maxheight="100";
$old_width=imagesx($src_img);
$old_height=imagesy($src_img);
if($maxheight>=$maxheight) {
   $new_height=$maxheight;
   $new_width=($new_height*$old_width)/$old_height;
}
if($img_ex=="jpg"){
$dst_img=imagecreatetruecolor($new_width,$new_height);
}else{
   $dst_img=imagecreate($new_width,$new_height);
}
ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_width,$new_height,$old_width,$old_height);
$smallname=$dir.$img_name.$small_ex.".".$img_ex;
switch($img_ex) {
   case "jpg":
   ImageJpeg($dst_img,$smallname,100);
   break;
   case "gif":
   imageGif($dst_img,$smallname,100);
   break;
}
}
阅读(2053) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~