이미지 리사이즈 > 그누보드5 팁자료실

그누보드5 팁자료실

이미지 리사이즈 정보

이미지 리사이즈

본문


function resize_image($file, $newfile, $w, $h)
{
list($width, $height) = getimagesize($file);
if(strpos(strtolower($file), ".jpg"))
$src = imagecreatefromjpeg($file);
else if(strpos(strtolower($file), ".png"))
$src = imagecreatefrompng($file);
else if(strpos(strtolower($file), ".gif"))
$src = imagecreatefromgif($file);
$dst = imagecreatetruecolor($w, $h);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $width, $height);
if(strpos(strtolower($newfile), ".jpg")) imagejpeg($dst, $newfile);
else if(strpos(strtolower($newfile), ".png")) imagepng($dst, $newfile);
else if(strpos(strtolower($newfile), ".gif")) imagegif($dst, $newfile);
}

 

폴더에 권한 꼭 주셔야합니다. chmod 707

사용은 아래와 같이 하면 됩니다.

resize_image("org/model.jpg", "new/model200.jpg", 200, 100); // 알아서 jpg 유형의 파일 생성 resize_image("org/model.jpg", "new/model200.png", 200, 100); // 알아서 png 유형의 파일 생성 resize_image("org/model.jpg", "new/model200.gif", 200, 100); // 알아서 gif 유형의 파일 생성

 

파일명이 순차적이라면 루프 돌리면 대량으로도 작업 가능하겠네요.

추천
1

댓글 3개

전체 2,432 |RSS
그누보드5 팁자료실 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT