2026, 새로운 도약을 시작합니다.

smarteditor2로 이미지 추가할 때 용량 줄이기

저용량 서버를 사용하시는 분에게 추천합니다.

smarteditor2에서 이미지 고용량 이미지 업로드 할때 서버에 무리가 갈수 있습니다.

또한 고용량 이미지 경우 유틸 프로그램 포함시킬수도 있습니다.

*** 에디터에서 이미지 축소하는 방법 

3732210772_1760277007.9824.png

editor/smarteditor2/photo_uploader/popup/php/UploadHandler.php

move_uploaded_file($uploaded_file, $file_path); 소스 아래 추가하시면 됩니다.

[code]

if (filesize($file_path) > 1024 * 1024) {
    $image_info = getimagesize($file_path);
    if ($image_info) {
        list($width, $height) = $image_info;
        $mime = $image_info['mime'];

        // 지원하는 mime 유형만 허용
        $allowed_mime_types = ['image/jpeg', 'image/png'];
        if (!in_array($mime, $allowed_mime_types)) {
            throw new Exception('Unsupported image format.');
        }

        // Exif 방향 처리 (JPEG만 해당)
        $orientation = 1;
        if ($mime === 'image/jpeg' && function_exists('exif_read_data')) {
            $exif = @exif_read_data($file_path);
            if (!empty($exif['Orientation'])) {
                $orientation = $exif['Orientation'];
            }
        }

        if ($width > 900) {
            $new_width = 900;
            $new_height = intval($height * ($new_width / $width));

            try {
                switch ($mime) {
                    case 'image/jpeg':
                        $src = imagecreatefromjpeg($file_path);
                        break;
                    case 'image/png':
                        $src = imagecreatefrompng($file_path);
                        break;
                    default:
                        throw new Exception('Unsupported image type');
                }

                // Exif 회전 보정
                switch ($orientation) {
                    case 3:
                        $src = imagerotate($src, 180, 0);
                        break;
                    case 6:
                        $src = imagerotate($src, -90, 0);
                        break;
                    case 8:
                        $src = imagerotate($src, 90, 0);
                        break;
                }

                $dst = imagecreatetruecolor($new_width, $new_height);

                // PNG 투명도 유지
                if ($mime === 'image/png') {
                    imagealphablending($dst, false);
                    imagesavealpha($dst, true);
                }

                imagecopyresampled(
                    $dst, $src,
                    0, 0, 0, 0,
                    $new_width, $new_height,
                    imagesx($src), imagesy($src)
                );

                switch ($mime) {
                    case 'image/jpeg':
                        imagejpeg($dst, $file_path, 85);
                        break;
                    case 'image/png':
                        imagepng($dst, $file_path);
                        break;
                }

                imagedestroy($src);
                imagedestroy($dst);
            } catch (Exception $e) {
                // 오류 로깅 또는 처리를 여기에 추가
                error_log($e->getMessage());
            }
        }
    }
}

[/code]

|

댓글 4개

감사합니다 ^^

감사 합니다.

감사합니다

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

그누보드5 팁자료실

번호 제목 글쓴이 날짜 조회
공지 3년 전 조회 4,596
2741 2일 전 조회 98
2740 4일 전 조회 93
2739 1주 전 조회 205
2738 1주 전 조회 208
2737 1주 전 조회 173
2736 1주 전 조회 275
2735 3주 전 조회 277
2734 3주 전 조회 258
2733 1개월 전 조회 261
2732 1개월 전 조회 298
2731 1개월 전 조회 263
2730 1개월 전 조회 221
2729 1개월 전 조회 349
2728 1개월 전 조회 243
2727 1개월 전 조회 418
2726 1개월 전 조회 251
2725 1개월 전 조회 325
2724 1개월 전 조회 356
2723 1개월 전 조회 264
2722 1개월 전 조회 297
2721 1개월 전 조회 210
2720 2개월 전 조회 303
2719 2개월 전 조회 306
2718 2개월 전 조회 199
2717 2개월 전 조회 334
2716 2개월 전 조회 201
2715 2개월 전 조회 310
2714 2개월 전 조회 270
2713 2개월 전 조회 373
2712 2개월 전 조회 288
🐛 버그신고