제목 Thumbnail Image (GD 처리)
등록자 관리자 등록일시 2006-05-15 조회수 245 HIT
// 제가 만들어쓰는 엔진에서 gd 처리 부분만 따로 적어보겠습니다.
참고해서 쓰십시오.

// 호출시
put_gdimage('원본파일명', 생성가로, 생성세로, '저장될파일명');

// 정상생성여부 확인시 : 정상생성시 1을 리턴, 이외는 실패

// gd 이미지 생성
// $img_name = 생성에 사용될 원본 파일명, $width = 생성이미지 가로크기, $height = 생성이미지 세로크기, $save_name = 저장될 파일명
function put_gdimage($img_name, $width, $height, $save_name){

    $gd = gd_info();
    $gdver = substr(preg_replace("/[^0-9]/", "", $gd['GD Version']), 0, 1);
    if(!$gdver) return "GD 버젼체크 실패거나 GD 버젼이 1 미만입니다.";

    $srcname = "../upload/goods/".$img_name;
    $timg = getimagesize($srcname);
    if($timg[2] != 1 && $timg[2] != 2 && $timg[2] != 3) return "확장자가 jp(e)g/png/gif 가 아닙니다.";

    // jpg, jpeg
    if($timg[2] == 2){
        
        $cfile = imagecreatefromjpeg($srcname);
        // gd 버전별로
        if($gdver == 2){
            $dest = imagecreatetruecolor($width, $height);
            imagecopyresampled($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
        }else{
            $dest = imagecreate($width, $height);
            imagecopyresized($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
        }
        imagejpeg($dest, "../upload/goods/".$save_name, 90);
    
    // png
    }else if($timg[2] == 3){

        $cfile = imagecreatefrompng($srcname);
        if($gdver == 2){
            $dest = imagecreatetruecolor($width, $height);
            imagecopyresampled($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
        }else{
            $dest = imagecreate($width, $height);
            imagecopyresized($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
        }
        imagepng($dest, "../upload/goods/".$save_name, 90);

    // gif
    }else if($timg[2] == 1){

        $cfile = imagecreatefromgif($srcname);
        if($gdver == 2){
            $dest = imagecreatetruecolor($width, $height);
            imagecopyresampled($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
        }else{
            $dest = imagecreate($width, $height);
            imagecopyresized($dest, $cfile, 0, 0, 0, 0, $width, $height, $timg[0], $timg[1]);
        }    
        imagegif($dest, "../upload/goods/".$save_name, 90);
    }
    // 메모리에 있는 그림 삭제
    imagedestroy($dest);
    return 1;
}

* 출처 : phpschool.com - sjsjin 님
목록보기

        X  
31  PHP7 클래스 선언 방법  2021-11-03 49
30  PHP7 배열 선언 코드  2021-11-03 336
29  PHP 코드를 최적화하는 40가지 팁 (번역)  2009-12-23 296
28  if , else 조건문 코드 줄이기 (?:)  2009-12-23 166
27  간단한 이메일 보내기 클래스  2008-03-05 252
26  업로드 이미지 사이즈 처리  2006-05-23 191
25  첨부 이미지(스샷) 사이즈 조정  2006-05-15 135
24  SMS 발송 - 명단 입력 스크립트  2005-09-16 135
23  PHP 로 TTF 파일을 웹폰트로 만들기  2006-05-28 276
22  glob -- Find pathnames matching a pattern  2006-05-18 196
 Thumbnail Image (GD 처리)  2006-05-15 245
20  PHP Fuction 검색 창 소스  2006-04-11 201
19  이미지 파일의 가로, 세로 픽셀 알아내기  2006-04-11 165
18  테스트용 변수 출력 소스  2006-04-06 168
17  리눅스 apache, php 에서 mssql connecting 하기  2005-06-07 347
16  php를 이용하여 서버 백업 프로그램 짜기  2004-05-04 311
15  베이비 헤로스 이벤트 소스  2004-04-28 143
14  세션 생성..  2004-04-21 200
13  제로보드 view.php 분석  2004-04-07 152
12  다중 게시판 검색  2004-03-25 1172
1 2