이미지 일괄 크기 조정
label{width:150px;display: inline-block;}
style> ;
class tool_slt_resize{ 공개 $width=null; 공개 $height=null; 공개 $Msg = null; 공개 $extension=array('jpg','gif','jpeg','png','bmp'); 공개 함수 __construct(){ 헤더('콘텐츠 유형 : text/html; charset=UTF-8'); } /** * 폴더의 모든 파일 읽기 * @param $src 폴더 경로 * @return bool */ 공용 함수 getAllFile($src,$new){ set_time_limit( 0); //PHP 스크립트는 무제한으로 실행됩니다. ob_end_clean(); //키 1 echo str_pad('',1024) //키 2 $handle=opendir( $src); //디렉토리 핸들 열기 while(($file=readdir($handle)) !== false){ //디렉토리의 모든 파일을 반복합니다. if($file != ' .' && $file != '..' ){ //현재 디렉터리나 상위 디렉터리가 아닌 경우 $fullPath = $src.'/'.$file //전체 경로를 가져옵니다. 현재 파일 $ newPath = $new.'/'.$file; //새 파일 저장 경로 $dir=dirname($newPath); if(!file_exists($dir)){ mkdir($ dir); } if(is_dir($fullPath)){ //폴더를 나타내는지 확인 $this->getAllFile($fullPath,$newPath) / /폴더인 경우 재귀적으로 함수 실행
}else{ //이미지 처리 시작
$extension=$this->get_extension($fullPath);
if(in_array($extentsion,$this) ->extension) ){ //접미사가 합법적인가요?
// echo $newPath.'';
$im = imagecreatefromjpeg($fullPath);
$width = Imagesx( $im);
$height = imagey($im);
$this->resize_to($im,$width,$height,$this->width,$this->height,$ fullPath,$newPath);
$msg= $fullPath.'처리 완료';
echo $msg;
flash(); //출력 버퍼 새로 고침
}
}
}
}
echo '모든 처리 완료';
}
/**
* 일부 이미지 정보 가져오기
* getimagesize는 4개 단위($width, $height, $type, $attr)의 배열을 반환합니다.
* @param $src
* @return 배열
*/
공개 함수 getImgInfo($src ){
return getimagesize($src);
}
/**
* 파일 접미사 가져오기
* @param $file
* @return 혼합
*/
함수 get_extension($file){
$info = pathinfo($file );
return strtolower($info['extension']);
}
//이미지 크기 조정
공개 함수 resize_to($image,$width,$height,$dst_width,$dst_height, $path,$dstpath) {
// set_time_limit(0);
$resize_width = 0;
$resize_height = 0;
if($dst_width && $width > $dst_width ){
$resize_width = 1 ;
$width_ratio = $dst_width/$width;
}
if($dst_height && $height > $dst_height){
$resize_height = 1;
$height_ratio = $dst_height/ $height;
}
if($resize_height&&$resize_width){
//너비 우선
if($width_ratio < $height_ratio){ $scale_org[ 0] = $width * $width_ratio; $scale_org[1] = $height * $width_ratio; } //고도수준 else{ $scale_org[0] = $width * $height_ratio; $scale_org[1] = $height * $height_ratio; } } elseif($resize_width){ $scale_org[0] = $dst_width; $scale_org[1] = $dst_width*$height/$width; } elseif($resize_height ){ $scale_org[0] = $dst_height*$width/$height; $scale_org[1] = $dst_height; } if(function_exists("imagecopyresampled")){ $newim = imagecreatetruecolor($scale_org[0], $scale_org[1]); imagecopyresampled($newim, $image, 0, 0, 0, 0, $scale_org[0], $scale_org[1] , $width, $height); }else{ $newim = imagecreate($scale_org[0], $scale_org[1]); imagecopyreized($newim, $image, 0, 0, 0, 0,$scale_org[0], $scale_org[1], $width, $height); } ImageJpeg($newim,$dstpath); ImageDestroy($newim); } } $a=new tool_slt_resize(); //接受表单数据开始处리리그림 $oldPath=isset($_GET['oldPath'])?$_GET['oldPath']:''; $newPath=isset($_GET['newPath' ])?$_GET['newPath']:''; $width=isset($_GET['width'])?$_GET['width']:''; $height=isset( $_GET['height'])?$_GET['height']:''; $a->width=$width;
$a->height=$height;
if (isset($_GET['submit'])){
if($oldPath==''||$newPath==''||$width==''){
echo '请正确填写表单';
종료;
}else{
$a->getAllFile($oldPath,$newPath);
}
}
?>
图文批weight缩放
harat文件夹< /label>
缩略图文件夹 < input type="text" name="newPath" value="">
缩略图宽degree
缩略图높이
< ;/body>
复代码