▶이동
  • 상구너 닷컴 블로그를 방문하신 여러분을 환영합니다 :)
  • 스팸 정책에 의해 일부 덧글·방명록차단될 수 있습니다.

구너갤러리 15.11

Develop 상구너(sanguneo) 2015. 11. 4. 18:12

구너갤러리가 개발되었습니다.


기본 기능

- 모바일/PC 반응형 웹

- PC이용시 키보드로 제어

- 한곡 반복

- 파일 하나로 하위디렉토리 전체 갤러리화

- 디렉토리 구분 출력

- 압축파일 다운로드 가능하도록 출력

- 외부 라이브러리 다운받을 필요 없도록 만듬.(jQuery 등)

- 이미지 바로 다운로드 받기 지원.



!! 파일 하나로 내 서버가 갤러리가된다!

!! one-file php image gallery 구너갤러리.


jQuery 플러그인과 swipebox 플러그인을 이용했습니다.(swipebox 는 약간의 수정이 있었습니다.)


두가지 파일이 필요합니다.

.htaccess 와 index.php 두개입니다.

아래 파일을 받아주세요.


Pictures.zip




1
2
3
// /Music/ 은 index.php 가 있는 경로(서버루트로부터의 상대경로)를 말합니다.
// .htaccess 는 아파치 웹서버를 사용시에 적용이되며 이를 지원하지 않는 환경에서는 기존방법을 이용하여야 합니다.
DirectoryIndex  /Pictures/index.php



아래는 index.php 의 php 부분입니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/**
 *
 * 구너갤러리 15.11
 *
 **/
$uri = rawurldecode(str_replace("/Pictures",".",$_SERVER["REQUEST_URI"]));
 
if(isset($_GET["dn"])&&$_GET["dn"]=="y"){
    $filepath = explode("?",$uri)[0].$_GET["path"];
    $path = explode("?",$uri)[0];
    $filesize = filesize($filepath);
    $path_parts = pathinfo($filepath);
    $filename = $path_parts['basename'];
    $extension = $path_parts['extension'];
    $mime = getImageSize($filepath)['mime'];
     
    header("Pragma: public");
    header("Expires: 0");
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"".$_GET["path"]."\"");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".$filesize);
      
    ob_clean();
    flush();
    readfile($filepath);
}
 
function startsWith($haystack, $needle) {return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== FALSE;}
function endsWith($haystack, $needle){ return $needle === "" || substr($haystack, -strlen($needle)) === $needle; }
function humanFileSize($size){
    if ($size >= 1073741824) {
        return round($size / 1024 / 1024 / 1024, 1) . 'GB';
    } elseif ($size >= 1048576) {
        return round($size / 1024 / 1024, 1) . 'MB';
    } elseif ($size >= 1024) {
        return round($size / 1024, 1) . 'KB';
    } else {
        return $size . ' bytes';
    }
    return '-';
}
function cut_str($str, $len, $suffix="…")
{
    $s = mb_strimwidth($str, 0, $len*2,"","utf-8");
    $cnt = 0;
    for ($i=0; $i<strlen($s); $i++)
        if (ord($s[$i]) > 127)
            $cnt++;
        $s = mb_strimwidth($str, 0, $len*2,"","utf-8");
    if (strlen($s) >= strlen($str))
        $suffix = "";
    return $s . $suffix;
}///변환된함수
 
// 원본 이미지 -> 썸네일로 만드는 함수
function thumbnail($file, $max_width, $max_height)
{
    global $uri;
        if(!file_exists($uri.".thumbnails/".$file)){
            $img_info = getImageSize($uri.$file);//원본이미지의 정보를 얻어옵니다
            $mime = $img_info['mime'];
            switch ($mime) {
                case 'image/jpeg':
                    $image_create_func = 'imagecreatefromjpeg';
                    $image_save_func = 'imagejpeg';
                    $quality = 100;
                    break;
                case 'image/png':
                    $image_create_func = 'imagecreatefrompng';
                    $image_save_func = 'imagepng';
                    $quality = 9;
                    break;
                case 'image/gif':
                    $image_create_func = 'imagecreatefromgif';
                    $image_save_func = 'imagegif';
                    break;
                default:
                    throw Exception('Unknown image type.');
            }
 
            $src_img = $image_create_func($uri.$file); //JPG파일로부터 이미지를 읽어옵니다
            $img_width = $img_info[0];
            $img_height = $img_info[1];
      
            if(($img_width/$max_width) == ($img_height/$max_height))
            {//원본과 썸네일의 가로세로비율이 같은경우
                $dst_width=$max_width;
                $dst_height=$max_height;
            }elseif(($img_width/$max_width) < ($img_height/$max_height))
            {//세로에 기준을 둔경우
                $dst_width=$max_height*($img_width/$img_height);
                $dst_height=$max_height;
            }else
            {//가로에 기준을 둔경우
                $dst_width=$max_width;
                $dst_height=$max_width*($img_height/$img_width);
            }
            $dst_img = imagecreatetruecolor($dst_width, $dst_height); //타겟이미지를 생성합니다
            switch ($mime) {
                case 'image/png':
                    $background = imagecolorallocate($dst_img, 0, 0, 0);
                    imagecolortransparent($dst_img, $background);
                    imagealphablending($dst_img, false);
                    imagesavealpha($dst_img, true);
                    break;
                case 'image/gif':
                    $background = imagecolorallocate($dst_img, 0, 0, 0);
                    // removing the black from the placeholder
                    imagecolortransparent($dst_img, $background);
                    break;
            }
            Imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $img_width, $img_height);
            $image_save_func($dst_img$uri.".thumbnails/".$file,$quality); //실제로 이미지파일을 생성합니다
            ImageDestroy($dst_img);
            ImageDestroy($src_img);
        }
        return ".thumbnails/".$file;
}
function dirlist(){
    global $uri;
    $default_dir = $uri;
    if (!$dh = @opendir($default_dir)) {
        return false;
    }
    $filelist = Array();
    $ziplist = Array();
    while (($file = readdir($dh)) !== false) {
        if (endsWith($file, "zip")||endsWith($file, "rar")||endsWith($file, "tar")||endsWith($file, "gz")||endsWith($file, "bz2"))
            array_push($ziplist,$file);
        if(startsWith($file,".") ||startsWith($file,"$") ||$file == "." || !is_dir($default_dir.$file))
            continue; // . , .. , 디렉토리는 무시
        array_push($filelist,$file);
    }
    array_push($filelist,"..");
    sort($filelist);
    foreach ($filelist as $dirname) {
        echo "<li class=\"nimg dir\" data-dirname=\"" . $dirname . "\">\n<div>\n" . $dirname . "</div></li>\n";
    }
    sort($ziplist);
    foreach ($ziplist as $dirname) {
        echo "<li class=\"nimg archive\" data-dirname=\"" . $dirname . "\">\n<a href=\"".$dirname."\">\n" . $dirname . "</a></li>\n";
    }
    closedir($dh);
}
 
function filelist(){
    global $uri;
    $default_dir = $uri;
    if (!$dh = @opendir($default_dir)) {
        return false;
    }
    $filelist = Array();
    $hereis = false;
    while (($file = readdir($dh)) !== false) {
        //if ($file == "." || $file == ".." || !endsWith($file, "mp3"))
        //    continue; // . 과 .. 디렉토리는 무시
        //$filelist[] = $file . "|" . humanFileSize(filesize($file));
        if(startsWith($file,"."))
            continue;
        if (endsWith($file, "jpg")||endsWith($file, "jpeg")||endsWith($file, "gif")||endsWith($file, "png")) {
            $filelist[] = $file . "|" . humanFileSize(filesize($default_dir.$file));
            $hereis = true;
        }
    }
    if($hereis){
        if(!file_exists($uri.".thumbnails")){
            if(mkdir($uri.".thumbnails", 0775,true)) {
                if(is_dir($uri.".thumbnails")) {
                    @chmod($uri.".thumbnails", 0775);
                }
            }
        }
    }
    sort($filelist);
    if(isset($filelist[1]))
        $filefirst = explode("|", $filelist[1])[0];
    foreach ($filelist as $filename) {
        echo "\t<li><a class=\"swipebox\" title=\"".explode("|", $filename)[0]."\" href=\"".explode("|", $filename)[0]."\"><ul class=\"listentity\" data=\"" . explode("|", $filename)[0] . "\">\n\t\t<li class=\"img\" style=\"background-image:url(" . thumbnail(explode("|", $filename)[0],"150","150") . ");\"></li><li class=\"mtitle\">" . cut_str(explode("|", $filename)[0],9) . "</li>\n\t\t</ul></a></li>\n";
    }
    if(isset($filelist[0]))
        $filefirst = explode("|", $filelist[0])[0];
    closedir($dh);
}
?>



설치는 대략 이렇습니다.


1. 이미지파일들이 잔뜩 있는 폴더(디렉토리)에 압축을 풀어 넣고

2. 에디터로 경로를 수정합니다.

3. 해당 페이지를 브라우저로 접속합니다.



사용상 문의는 댓글로 ^^



'Develop' 카테고리의 다른 글

개발자 후원하기.  (0) 2016.07.13
구너갤러리 15.11.2  (0) 2015.11.16
구너 플레이어 15.11  (1) 2015.11.04
베지에 곡선 (Bezier Curve)  (1) 2015.09.04
[구너 플레이어] 15.8 단일파일 php 음악 플레이어.  (4) 2015.08.06