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

정보공유

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


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



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

$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 470건 8 페이지
번호 제목 글쓴이 날짜 조회
365 phpMyAdmin 좌측 트리메뉴 테이블 갯수 설정 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 12-10 19,539
364 텍스트 복사 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 12-03 19,797
363 MYSQL LOCK TABLES 내 별칭(AS) 사용 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11-25 19,401
362 랜덤 아이디 문자열 생성 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11-13 21,365
361 설문응답 유효성 검사 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11-13 19,432
360 스마트에디터 배경 색상변경방법 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11-08 21,176
359 Chrome 브라우저 80 버전 로그인이 안되는 현상 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10-02 20,041
358 글 정렬을 날짜순으로 했더니 답글 순서가 안맞는경우. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-18 28,934
357 크롬에서 결제만 되고 정상적으로 처리가 되지 않는 경우 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-14 37,101
356 .htaccess 파일 https 로 자동변환 처리. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-04 20,755
355 정규식 제거 및 특정 태그 제거 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-02 25,830
354 javascript 동시 실행 테스트 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 07-01 21,796
353 그누보드 휴대폰관리에서 전체선택을 해도 전체목록이 나오지 않는 문제 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 06-25 22,669
352 javascript 만나이 계산 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 06-17 24,851
351 7.3 버전 주의사항 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 05-18 22,277