위토즈 - 개발자프로그램판매공간

정보공유

[그누보드팁] 게시물에 등록된 이미지파일 썸네일 생성 하고 워터마크 처리 하기


첨부된 이미지파일을 썸네일생성하고 워터마크 이미지파일을 별도로 생성하는 소스



//업로드 이미지 가져오기

$view = get_view($write, $board, $board_skin_path);

$thumb_width = 300; // 썸네일 가로 사이즈

$watermark_path = G5_PATH.'/watermark/watermark_logo.png';

$watermark_type = strtolower(substr($watermark_path, strlen($watermark_path)-4, 4));


$v_img_count = count($view['file']);

if($v_img_count) {

    for ($i=0; $i<=count($view['file']); $i++) {


        $srcfile = G5_DATA_PATH.'/file/'.$bo_table.'/'.$view['file'][$i]['file'];

        $waterfile = G5_DATA_PATH.'/file/'.$bo_table.'/water_'.$view['file'][$i]['file'];

        if(is_file($srcfile)) {

            $size = @getimagesize($srcfile);

            if(empty($size))

                continue;


            // jpg 이면 exif 체크

            if($size[2] == 2 && function_exists('exif_read_data')) {

                $degree = 0;

                $exif = @exif_read_data($srcfile);

                if(!empty($exif['Orientation'])) {

                    switch($exif['Orientation']) {

                        case 8:

                            $degree = 90;

                            break;

                        case 3:

                            $degree = 180;

                            break;

                        case 6:

                            $degree = -90;

                            break;

                    }


                    // 세로사진의 경우 가로, 세로 값 바꿈

                    if($degree == 90 || $degree == -90) {

                        $tmp = $size;

                        $size[0] = $tmp[1];

                        $size[1] = $tmp[0];

                    }

                }

            }


            // 원본 width가 thumb_width보다 작다면

            if($size[0] <= $thumb_width)

                continue;


            // Animated GIF 체크

            $is_animated = false;

            if($size[2] == 1) {

                $is_animated = is_animated_gif($srcfile);

            }


            // 썸네일 높이

            $thumb_height = round(($thumb_width * $size[1]) / $size[0]);

            $filename = basename($srcfile);

            $filepath = dirname($srcfile);


            // 워터마크 파일 생성

            $align_center = true;

            $image_type = strtolower(substr($srcfile, strlen($srcfile)-4, 4));

            if ($image_type == '.bmp') $image = imagecreatefromwbmp($srcfile);

            if ($image_type == '.gif') $image = imagecreatefromgif($srcfile);

            if ($image_type == '.jpg') $image = imagecreatefromjpeg($srcfile);

            if ($image_type == '.png') $image = imagecreatefrompng($srcfile);


            if ($watermark_type == '.bmp') $watermark = imagecreatefromwbmp($watermark_path);

            if ($watermark_type == '.gif') $watermark = imagecreatefromgif($watermark_path);

            if ($watermark_type == '.jpg') $watermark = imagecreatefromjpeg($watermark_path);

            if ($watermark_type == '.png') $watermark = imagecreatefrompng($watermark_path);


            if($image && $watermark) {


                list($image_w, $image_h) = getimagesize($srcfile);

                list($watermark_w, $watermark_h) = getimagesize($watermark_path);


                if($align_center) { // Center

                    $pos_x = (($image_w - $watermark_w)/2);

                    $pos_y = (($image_h - $watermark_h)/2);

                }

                else {

                    $pos_x = ($image_w - $watermark_w);

                    $pos_y = ($image_h - $watermark_h);

                }

                imagealphablending($image, true);

                imagecopy($image, $watermark, $pos_x, $pos_y, 0, 0, $watermark_w, $watermark_h);

                imagejpeg($image, $waterfile, 100);

                imagedestroy($image);

                imagedestroy($watermark);

            }


            // 썸네일 생성

            if(!$is_animated)

                $thumb_file = thumbnail($filename, $filepath, $filepath, $thumb_width, $thumb_height, false);

            else

                $thumb_file = $filename;


            if(!$thumb_file)

                continue;


            echo '<img src="'.G5_DATA_URL.'/file/'.$bo_table.'/'.$thumb_file.'"/>';

        }

    }

}


정보공유
Total 434건 1 페이지
번호 제목 글쓴이 날짜 조회
434 입금된 주문도 준비, 배송전까지는 취소할 수 있도록 하는 방법 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-10 482
433 CSS를 사용하여 4x4 형태의 갤러리 디자인 그리드 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-05 477
432 magnificPopup css 를 추가하여 popup 마다 다른 사이즈 로 띄우기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-16 1021
431 magnificPopup 조건이 맞지 않으면 popup 띄우지 않기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-12 923
430 magnificPopup iframe 으로 form submit 하기 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-12 1052
429 mysql 사용자 함수 생성 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-09 827
428 html 로 된 svg 태그를 png 파일로 만들기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-08 1044
427 prepare bind_param 쿼리구분 select * 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 08-14 1653
426 javascript 플랫폼 디바이스 확인 함수 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 07-13 1748
425 stmt 등록 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 06-14 2052
424 prepare 함수 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 05-16 2028
423 magnificPopup 으로 창을 호출 후 날짜 입력박스에 datepicker 실행되지 않는경우 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 04-13 1977
422 magnificPopup 파라미터 변수 값 ajax 타입으로 전송 방법 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-31 2028
421 jquery 로 text 필드와 file 첨부를 동시에. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-09 2161
420 파일 첨부 를 이미지버튼으로 대체한경우 첨부한 파일명 표시하기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-09 2140