缺点:长宽不一的图片会被拉伸变形,不能智能裁切,需要智能裁切的,请自行研究。 <?php $config=array(); $config['path']="./"; $config['t_width']=120; $config['theight']=98; $config['ignore']=array("",".",".."); $config['prefix']="thumb"; $done=0; define("IMAGE_JPG",2); define("ENDL","n"); if($handle=opendir($config['path'])){ while(false!==($file=readdir($handle))){ if(!array_search($file,$config['ignore'])){ list($im_width,$im_height,$type)=getimagesize($file); if($type!=IMAGE_JPG){ continue; } $op.="found-><ahref='{$file}'>$file".ENDL; $im=@imagecreatefromjpeg($file); if(!$im){ $op.="fail->couldn'tcreatesourimagepointer.".ENDL; continue; } if(file_exists($config['prefix'].$file)||substr($file,strlen($config['prefix']))==$config['prefix']){ $op.="note->thisfilehasalreadygotathumbnail.".ENDL; continue; } $to=imagecreatetruecolor($config['t_width'],$config['t_height']); if(!$to){ $op.="fail->couldn'tcreatedestimagepointer.".ENDL; continue; } if(!imagecopyresampled($to,$im,$config['t_width'],$config['t_height'],$im_width,$im_height)){ $op.="fail->couldn'tcreatethumbnail.phpfail.".ENDL; continue; } //保存文件 imagejpeg($to,$config['prefix'].$file); $op.="done->createdthumb:<ahref='{$config['prefix']}{$file}'>{$config['prefix']}{$file}".ENDL; $done++; } } } closedir($handle); $op.="fin->{$done}file(s)written".ENDL; echo" "; echo$op; echo" "; exit; ?> (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|