첨부파일 이미지 리사이징..

첨부파일 이미지 리사이징..

QA

첨부파일 이미지 리사이징..

본문

앞단에서는


<input type="file" name="head_logo" id="head_logo">

이렇게 넣었고

update되는 페이지에서는


if ($_FILES['head_logo']['name']) upload_file($_FILES['head_logo']['tmp_name'], $wr_id."_1.png", G5_DATA_PATH."/common");

이렇게 넣었습니다.

물론 이미지는 잘올라갑니다...

그런데 모바일에서 첨부파일로 등록중인데

용량이 10M가 넘다보니 서버용량이 너무 금방 차버립니다...

업로드를하고 리사이징을 하여 다시 업로드되고 좋고

업로드를 할때에 리사이징해여 작게해서 업로드를 해도 좋은데

방법좀 알고싶습니다...

이 질문에 댓글 쓰기 :

답변 1


    if ($_FILES['head_logo']['name']) {

        $img_limit_width = 660; // 제한할 이미지 폭
        $img_quality = 70; // 이미지 품질

        $data_path = G5_DATA_PATH."/common";

        $file = $data_path .'/'. $wr_1;
        if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file)) {
            $size = getimagesize($file);
            if ($size[2] == 1){
                $src = imagecreatefromgif($file);
				//echo "1222";
			}
            else if ($size[2] == 2){
                $src = imagecreatefromjpeg($file);
				//echo "2222";
			}
            else if ($size[2] == 3){
                $src = imagecreatefrompng($file);
				//echo "3222";
			}

            $rate = $img_limit_width / $size[0];
            $height = (int)($size[1] * $rate);

            if ($size[0] > $img_limit_width){

                @unlink($data_path.'/'.$wr_1);
                $dst = imagecreatetruecolor($img_limit_width, $height);
                imagecopyresampled($dst, $src, 0, 0, 0, 0, $img_limit_width, $height, $size[0], $size[1]);
                imagejpeg($dst, $data_path.'/'.$wr_1, $img_quality);
                chmod($data_path.'/'.$wr_1, 0606);
                $bf_size = @filesize(addslashes($file));
            }
        }
    }
답변을 작성하시기 전에 로그인 해주세요.
전체 124,673 | RSS
QA 내용 검색

회원로그인

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