├── README.md
├── index.php
└── thumb.php
/README.md:
--------------------------------------------------------------------------------
1 | Community
2 | ============
3 | Quick Gallery now has a community forum open to everyone. https://www.pilabs.io/forum/
4 |
5 | QuickGallery
6 | ============
7 |
8 | Quick Gallery allows you to upload image folders to make an online gallery with support for multiple image galleries.
9 |
10 | Supports by default: png, jpg, jpeg, and gif but you are able to extend this by modifying line 53:
11 |
12 | ```$allowed_types = array('png','jpg','jpeg','gif');```
13 |
14 | Screenshot
15 | ============
16 | 
17 |
18 | Instructions
19 | ============
20 | 1. Download index.php and thumb.php
21 | 2. Upload to a folder accessible by the internet (e.g. A folder called "gallery")
22 | 3. Upload image albums to their own folder.
23 | 4. Profit???
24 |
25 | To enable caching, create a folder in the root of your gallery folder called "cache" and it give it 777 permissions.
26 |
27 | File Tree Example
28 | ============
29 | gallery
30 | ├── cache
31 | ├── index.php
32 | ├── simcity
33 | │ ├── Spark_2013-03-18_15-12-33.png
34 | │ ├── Spark_2013-03-18_15-25-06.png
35 | │ ├── Spark_2013-03-18_15-25-18.png
36 | │ ├── Spark_2013-03-18_15-25-35.png
37 | │ ├── Spark_2013-03-18_15-25-50.png
38 | ├── team fortress 2
39 | │ ├── 2011-02-24_00001.jpg
40 | │ ├── 2011-05-09_00001.jpg
41 | │ ├── 2011-05-09_00002.jpg
42 | ├── thumb.php
43 |
44 | Requirements
45 | ============
46 | * PHP + PHP GD
47 | * Web Server
48 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
18 |
19 |
20 |
21 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | $value ) {
44 | if (in_array($value, $disable) === FALSE) {
45 | //This is not set to work if you didn't have an nginx/apache2 rewrite rule for folders
46 | //You can create a rewrite rule and modify the link accordingly below.
47 | echo ''.$value.' ';
48 | }
49 | }
50 | ?>
51 |
52 |
53 |
Quick Gallery by Michael Ojeda
54 |
55 |
56 |
"; }
68 | ?>
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/thumb.php:
--------------------------------------------------------------------------------
1 |
37 |
38 | Where:
39 | FILE = the file to retrieve
40 | SIZE = the maximum size of the thumbnail in pixels
41 | ______________________________________________________________________
42 | Changes:
43 | 0.1 - first release
44 | 0.2 - converted cache thumbnail from png to jpeg
45 | 0.3 - fixed error where files weren't being cached properly
46 | 0.4 - allowed non local urls (if allow_url_fopen is on), quality and nocache switches
47 | 0.5 - allowed maximum x and y settings (for scaling images to fit non square sizes)
48 | 0.6 - allowed tagging of images (with the get query placing the text in the bottom left hand corner of the image)
49 | 0.7 - fixed gd_info error for php<4.3
50 | 0.8 - added gif support (for gd 2.0.28)
51 | 0.9 - now supports native outputting of png, jpg and gif formats
52 | 1.0 - doesn't fail if the cache file can't be created
53 | 1.1 - removed a few more notices
54 | */
55 | //script configuration
56 | ini_set('memory_limit','64M');
57 | $site_config['document_root'] = $_SERVER['DOCUMENT_ROOT'];
58 | $thumb_size = 211; //all thumbnails are this maximum width or height if not specified via get
59 | $site_config['absolute_uri']=str_replace('///','//',str_replace('thumb.php?'.$_SERVER['QUERY_STRING'],'',$_SERVER['REQUEST_URI']));
60 | $site_config['path_thumbnail']=$site_config['absolute_uri'].'cache/'; //where to cache thumbnails on the server, relative to the DOCUMENT_ROOT
61 | $image_error=$site_config['document_root'].$site_config['absolute_uri'].'/images/icons/image_error.png'; // used if no image could be found, or a gif image is specified
62 |
63 | $thumb_size_x = 0;
64 | $thumb_size_y = 0;
65 |
66 | # Define quality of image
67 | if (@$_GET["quality"]<>0) {
68 | $quality = $_GET["quality"];
69 | } else {
70 | $quality = 80;
71 | }
72 |
73 | # Define size of image (maximum width or height)- if specified via get.
74 | if (@$_GET["size"]<>0) {
75 | $thumb_size=intval($_GET["size"]);
76 | }
77 | if (intval(@$_GET["sizex"])>0)
78 | {
79 | $thumb_size_x=intval($_GET["sizex"]);
80 | if (intval(@$_GET["sizey"])>0)
81 | {
82 | $thumb_size_y=intval($_GET["sizey"]);
83 | } else {
84 | $thumb_size_y=$thumb_size_x;
85 | }
86 | }
87 |
88 | if (file_exists($_GET['file']))
89 | {
90 | $filename=$_GET['file'];
91 | } else {
92 | $filename=str_replace('//','/',$site_config['document_root'].$site_config['absolute_uri'].'/'.$_GET["file"]);
93 | }
94 |
95 | # If calling an external image, remove document_root
96 | if (substr_count($filename, "http://")>0)
97 |
98 |
99 | {
100 | $filename=str_replace($site_config['document_root'].$site_config['absolute_uri'].'/','',$filename);
101 | }
102 |
103 | $filename=str_replace("\'","'",$filename);
104 | $filename=rtrim($filename);
105 | $filename=str_replace("//","/",$filename);
106 | $fileextension=substr($filename, strrpos ($filename, ".") + 1);
107 |
108 | $cache_file=str_replace('//','/',$site_config['document_root'].$site_config['path_thumbnail'].md5($filename.@$thumb_size.@$thumb_size_x.@$thumb_size_y.@$quality).'.'.$fileextension);
109 |
110 | # remove cache thumbnail?
111 | if (@$_GET['nocache']==1)
112 | {
113 | if (file_exists($cache_file))
114 | {
115 | #remove the cached thumbnail
116 | unlink($cache_file);
117 | }
118 | }
119 |
120 | if ((file_exists($cache_file)) && (@filemtime($cache_file)>@filemtime($filename)))
121 | {
122 | header('Content-type: image/'.$fileextension);
123 | header("Expires: Mon, 26 Jul 2030 05:00:00 GMT");
124 | header('Content-Disposition: inline; filename='.str_replace('/','',md5($filename.$thumb_size.$thumb_size_x.$thumb_size_y.$quality).'.'.$fileextension));
125 | echo (join('', file( $cache_file )));
126 | exit; # no need to create thumbnail - it already exists in the cache
127 | }
128 |
129 | # determine php and gd versions
130 | $ver=intval(str_replace(".","",phpversion()));
131 | if ($ver>=430)
132 | {
133 | $gd_version=@gd_info();
134 | }
135 |
136 | # define the right function for the right image types
137 | if (!$image_type_arr = @getimagesize($filename))
138 | {
139 | header('Content-type: image/png');
140 | if(@$_GET['noerror'])
141 | {
142 | exit;
143 | } else {
144 | echo (join('', file( $site_config['document_root'].$image_error )));
145 | exit;
146 | }
147 | }
148 | $image_type=$image_type_arr[2];
149 |
150 | switch ($image_type)
151 | {
152 | case 2: # JPG
153 | if (!$image = @imagecreatefromjpeg ($filename))
154 | {
155 | # not a valid jpeg file
156 | $image = imagecreatefrompng ($image_error);
157 | $file_type="png";
158 | if (file_exists($cache_file))
159 | {
160 | # remove the cached thumbnail
161 | unlink($cache_file);
162 | }
163 | }
164 | break;
165 |
166 | case 3: # PNG
167 | if (!$image = @imagecreatefrompng ($filename))
168 | {
169 | # not a valid png file
170 | $image = imagecreatefrompng ($image_error);
171 | $file_type="png";
172 | if (file_exists($cache_file))
173 | {
174 | # remove the cached thumbnail
175 | unlink($cache_file);
176 | }
177 | }
178 | break;
179 |
180 | case 1: # GIF
181 | if (!$image = @imagecreatefromgif ($filename))
182 | {
183 | # not a valid gif file
184 | $image = imagecreatefrompng ($image_error);
185 | $file_type="png";
186 | if (file_exists($cache_file))
187 | {
188 | # remove the cached thumbnail
189 | unlink($cache_file);
190 | }
191 | }
192 | break;
193 | default:
194 | $image = imagecreatefrompng($image_error);
195 | break;
196 |
197 | }
198 |
199 | # define size of original image
200 | $image_width = imagesx($image);
201 | $image_height = imagesy($image);
202 |
203 | # define size of the thumbnail
204 | if (@$thumb_size_x>0)
205 | {
206 | # define images x AND y
207 | $thumb_width = $thumb_size_x;
208 | $factor = $image_width/$thumb_size_x;
209 | $thumb_height = intval($image_height / $factor);
210 | if ($thumb_height>$thumb_size_y)
211 | {
212 | $thumb_height = $thumb_size_y;
213 | $factor = $image_height/$thumb_size_y;
214 | $thumb_width = intval($image_width / $factor);
215 | }
216 | } else {
217 | # define images x OR y
218 | $thumb_width = $thumb_size;
219 | $factor = $image_width/$thumb_size;
220 | $thumb_height = intval($image_height / $factor);
221 | if ($thumb_height>$thumb_size)
222 | {
223 | $thumb_height = $thumb_size;
224 | $factor = $image_height/$thumb_size;
225 | $thumb_width = intval($image_width / $factor);
226 | }
227 | }
228 |
229 | # create the thumbnail
230 | if ($image_width < 4000) //no point in resampling images larger than 4000 pixels wide - too much server processing overhead - a resize is more economical
231 | {
232 | if (substr_count(strtolower($gd_version['GD Version']), "2.")>0)
233 | {
234 | //GD 2.0
235 | $thumbnail = ImageCreateTrueColor($thumb_width, $thumb_height);
236 | imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_width, $image_height);
237 | } else {
238 | //GD 1.0
239 | $thumbnail = imagecreate($thumb_width, $thumb_height);
240 | imagecopyresized($thumbnail, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_width, $image_height);
241 | }
242 | } else {
243 | if (substr_count(strtolower($gd_version['GD Version']), "2.")>0)
244 | {
245 | # GD 2.0
246 |
247 | $thumbnail = ImageCreateTrueColor($thumb_width, $thumb_height);
248 | imagecopyresized($thumbnail, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_width, $image_height);
249 | } else {
250 | # GD 1.0
251 | $thumbnail = imagecreate($thumb_width, $thumb_height);
252 | imagecopyresized($thumbnail, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $image_width, $image_height);
253 | }
254 | }
255 |
256 | # insert string
257 | if (@$_GET['tag']<>"")
258 | {
259 | $font=1;
260 | $string= $_GET['tag'];
261 | $white = imagecolorallocate ($thumbnail, 255, 255, 255);
262 | $black = imagecolorallocate ($thumbnail, 0, 0, 0);
263 | imagestring ($thumbnail, $font, 3, $thumb_height-9, $string, $black);
264 | imagestring ($thumbnail, $font, 2, $thumb_height-10, $string, $white);
265 | }
266 |
267 | switch ($image_type)
268 | {
269 | case 2: # JPG
270 | header('Content-type: image/jpeg');
271 | header('Content-Disposition: inline; filename='.str_replace('/','',md5($filename.$thumb_size.$thumb_size_x.$thumb_size_y.$quality).'.jpeg'));
272 | @imagejpeg($thumbnail,$cache_file);
273 | imagejpeg($thumbnail);
274 |
275 | break;
276 | case 3: # PNG
277 | header('Content-type: image/png');
278 | header('Content-Disposition: inline; filename='.str_replace('/','',md5($filename.$thumb_size.$thumb_size_x.$thumb_size_y.$quality).'.png'));
279 | @imagepng($thumbnail,$cache_file);
280 | imagepng($thumbnail);
281 | break;
282 |
283 | case 1: # GIF
284 | if (function_exists('imagegif'))
285 | {
286 | header('Content-type: image/gif');
287 | header('Content-Disposition: inline; filename='.str_replace('/','',md5($filename.$thumb_size.$thumb_size_x.$thumb_size_y.$quality).'.gif'));
288 | @imagegif($thumbnail,$cache_file);
289 | imagegif($thumbnail);
290 | } else {
291 | header('Content-type: image/jpeg');
292 | header('Content-Disposition: inline; filename='.str_replace('/','',md5($filename.$thumb_size.$thumb_size_x.$thumb_size_y.$quality).'.jpg'));
293 | @imagejpeg($thumbnail,$cache_file);
294 | imagejpeg($thumbnail);
295 | }
296 | break;
297 | }
298 |
299 | //clear memory
300 | imagedestroy ($image);
301 | imagedestroy ($thumbnail);
302 |
303 | ?>
--------------------------------------------------------------------------------