w

이미지 리사이즈

[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개

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

그누보드5 팁자료실

+
제목 글쓴이 날짜 조회
2년 전 조회 1,595
2년 전 조회 2,625
2년 전 조회 2,270
2년 전 조회 2,272
2년 전 조회 2,018
2년 전 조회 4,225
2년 전 조회 3,113
2년 전 조회 2,255
2년 전 조회 1,760
2년 전 조회 2,280
2년 전 조회 2,160
2년 전 조회 1,641
2년 전 조회 1,580
2년 전 조회 2,593
2년 전 조회 1,890
2년 전 조회 1,431
2년 전 조회 3,237
2년 전 조회 1,410
2년 전 조회 1,935
2년 전 조회 1,933
2년 전 조회 1,646
2년 전 조회 1,436
2년 전 조회 2,560
2년 전 조회 2,172
2년 전 조회 1,910
2년 전 조회 1,706
2년 전 조회 2,188
2년 전 조회 2,589
2년 전 조회 2,043
2년 전 조회 2,374