테스트 사이트 - 개발 중인 베타 버전입니다

이미지 리사이즈

· 2년 전 · 1756 · 3

[code]

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);

}

[/code]

 

폴더에 권한 꼭 주셔야합니다. 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 유형의 파일 생성

 

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

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 3개

감사합니다.
감사합니다.
2년 전
감사합니다.

게시글 목록

번호 제목
24318
24317
24315
24309
24294
24293
24277
24262
24260
24253
24251
24236
24233
24228
24226
24221
24214
24203
24201
24199
24196
24195
24194
24192
24191
24187
24185
24183
24172
24168