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개

감사합니다.
감사합니다.
댓글을 작성하시려면 로그인이 필요합니다.
+
제목 글쓴이 날짜 조회
23-05-12 조회 5,196
23-05-10 조회 5,283
23-05-08 조회 5,714
23-05-04 조회 8,867
23-04-26 조회 5,486
23-04-24 조회 6,540
23-04-22 조회 5,377
23-04-22 조회 4,771
23-04-17 조회 5,777
23-04-16 조회 5,460
23-04-16 조회 5,335
23-04-15 조회 5,407
23-04-15 조회 7,491
23-04-14 조회 6,359
23-04-14 조회 5,430
23-04-13 조회 5,051
23-04-12 조회 5,462
23-04-11 조회 5,341
23-04-11 조회 4,793
23-04-09 조회 4,702
23-04-06 조회 5,783
23-04-05 조회 4,924
23-04-05 조회 4,523
23-04-03 조회 6,499
23-03-29 조회 4,462
23-03-29 조회 5,055
23-03-29 조회 5,052
23-03-29 조회 4,614
23-03-24 조회 4,505
23-03-23 조회 5,795