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

정보공유

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


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



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

$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 60건 1 페이지
번호 제목 글쓴이 날짜 조회
60 Click jacking, Frame sniffing 등과 같은 Frame을 이용한 공격 방어 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10-05 3746
59 쿠키 Secure 속성 옵션 추가. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10-05 3685
58 쿠키 하이젝킹 방지(cookie hijacking) HttpOnly, 쿠키 HttpOnly 속성 누락. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10-05 3765
57 SQL 인젝션 막기를 위한 php 코드 수정. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-08 3900
56 그누보드 clean_xss_tags 함수 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 07-28 4512
55 예약업 플러그인 이니시스 결제모듈 설치 안내 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-03 8221
54 예약업 플러그인 KCP 결제모듈 설치 안내 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-03 7733
53 목록화면 기본 코드 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 05-04 8293
52 그누보드, 영카트 다음API 우편번호 오류 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-16 12088
51 아이코드 예약 문자발송시 오류 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-10 10001
50 랜덤 아이디 문자열 생성 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11-13 12760
49 스마트에디터 배경 색상변경방법 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11-08 13068
48 글 정렬을 날짜순으로 했더니 답글 순서가 안맞는경우. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-18 18253
47 크롬에서 결제만 되고 정상적으로 처리가 되지 않는 경우 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-14 24456
46 그누보드 휴대폰관리에서 전체선택을 해도 전체목록이 나오지 않는 문제 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 06-25 14225