|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* @package phpBB Gallery Core |
|
6
|
|
|
* @copyright (c) 2014 nickvergessen |
|
7
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace phpbbgallery\core\file; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* A little class for all the actions that the gallery does on images. |
|
15
|
|
|
* |
|
16
|
|
|
* resize, rotate, watermark, crete thumbnail, write to hdd, send to browser |
|
17
|
|
|
* |
|
18
|
|
|
* @property \phpbbgallery\core\url url |
|
19
|
|
|
* @property \phpbb\request\request request |
|
20
|
|
|
*/ |
|
21
|
|
|
class file |
|
22
|
|
|
{ |
|
23
|
|
|
const THUMBNAIL_INFO_HEIGHT = 16; |
|
24
|
|
|
const GDLIB1 = 1; |
|
25
|
|
|
const GDLIB2 = 2; |
|
26
|
|
|
|
|
27
|
|
|
public $chmod = 0644; |
|
28
|
|
|
|
|
29
|
|
|
public $errors = array(); |
|
30
|
|
|
private $browser_cache = true; |
|
31
|
|
|
private $last_modified = 0; |
|
32
|
|
|
|
|
33
|
|
|
public $gd_version = 0; |
|
34
|
|
|
|
|
35
|
|
|
public $image; |
|
36
|
|
|
public $image_content_type; |
|
37
|
|
|
public $image_name = ''; |
|
38
|
|
|
public $image_quality = 100; |
|
39
|
|
|
public $image_size = array(); |
|
40
|
|
|
public $image_source = ''; |
|
41
|
|
|
public $image_type; |
|
42
|
|
|
|
|
43
|
|
|
public $max_file_size = 0; |
|
44
|
|
|
public $max_height = 0; |
|
45
|
|
|
public $max_width = 0; |
|
46
|
|
|
|
|
47
|
|
|
public $resized = false; |
|
48
|
|
|
public $rotated = false; |
|
49
|
|
|
|
|
50
|
|
|
public $thumb_height = 0; |
|
51
|
|
|
public $thumb_width = 0; |
|
52
|
|
|
|
|
53
|
|
|
public $watermark; |
|
54
|
|
|
public $watermark_size = array(); |
|
55
|
|
|
public $watermark_source = ''; |
|
56
|
|
|
public $watermarked = false; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Constructor - init some basic stuff |
|
60
|
|
|
* |
|
61
|
|
|
* @param \phpbb\request\request $request |
|
62
|
|
|
* @param \phpbbgallery\core\url $url |
|
63
|
|
|
* @param \phpbbgallery\core\config $gallery_config |
|
64
|
|
|
* @param int $gd_version |
|
65
|
|
|
*/ |
|
66
|
96 |
|
public function __construct(\phpbb\request\request $request, \phpbbgallery\core\url $url, \phpbbgallery\core\config $gallery_config, $gd_version) |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
96 |
|
$this->request = $request; |
|
69
|
96 |
|
$this->url = $url; |
|
70
|
96 |
|
$this->gallery_config = $gallery_config; |
|
|
|
|
|
|
71
|
96 |
|
$this->gd_version = $gd_version; |
|
72
|
96 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function set_image_options($max_file_size, $max_height, $max_width) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->max_file_size = $max_file_size; |
|
77
|
|
|
$this->max_height = $max_height; |
|
78
|
|
|
$this->max_width = $max_width; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function set_image_data($source = '', $name = '', $size = 0, $force_empty_image = false) |
|
82
|
|
|
{ |
|
83
|
|
|
if ($source) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->image_source = $source; |
|
86
|
|
|
} |
|
87
|
|
|
if ($name) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->image_name = $name; |
|
90
|
|
|
} |
|
91
|
|
|
if ($size) |
|
92
|
|
|
{ |
|
93
|
|
|
$this->image_size['file'] = $size; |
|
94
|
|
|
} |
|
95
|
|
|
if ($force_empty_image) |
|
96
|
|
|
{ |
|
97
|
|
|
$this->image = null; |
|
98
|
|
|
$this->watermarked = false; |
|
99
|
|
|
$this->rotated = false; |
|
100
|
|
|
$this->resized = false; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Get image mimetype by filename |
|
106
|
|
|
* |
|
107
|
|
|
* Only use this, if the image is secure. As we created all these images, they should be... |
|
108
|
|
|
* @param $filename |
|
109
|
|
|
* @return string |
|
110
|
|
|
*/ |
|
111
|
|
|
static public function mimetype_by_filename($filename) |
|
112
|
|
|
{ |
|
113
|
|
|
switch (utf8_substr(strtolower($filename), -4)) |
|
|
|
|
|
|
114
|
|
|
{ |
|
115
|
|
|
case '.png': |
|
116
|
|
|
return 'image/png'; |
|
117
|
|
|
break; |
|
|
|
|
|
|
118
|
|
|
case '.gif': |
|
119
|
|
|
return 'image/gif'; |
|
120
|
|
|
break; |
|
121
|
|
|
case 'jpeg': |
|
122
|
|
|
case '.jpg': |
|
123
|
|
|
return 'image/jpeg'; |
|
124
|
|
|
break; |
|
125
|
|
|
case '.webp': |
|
126
|
|
|
return 'image/webp'; |
|
127
|
|
|
break; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return ''; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Read image |
|
135
|
|
|
* @param bool $force_filesize |
|
136
|
|
|
* @return bool |
|
137
|
|
|
*/ |
|
138
|
|
|
public function read_image($force_filesize = false) |
|
139
|
|
|
{ |
|
140
|
|
|
if (!file_exists($this->image_source)) |
|
141
|
|
|
{ |
|
142
|
|
|
return false; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
switch (utf8_substr(strtolower($this->image_source), -4)) |
|
|
|
|
|
|
146
|
|
|
{ |
|
147
|
|
|
case '.png': |
|
148
|
|
|
$this->image = imagecreatefrompng($this->image_source); |
|
149
|
|
|
imagealphablending($this->image, true); // Set alpha blending on ... |
|
150
|
|
|
imagesavealpha($this->image, true); // ... and save alphablending! |
|
151
|
|
|
$this->image_type = 'png'; |
|
152
|
|
|
break; |
|
153
|
|
|
case '.webp': |
|
154
|
|
|
$this->image = imagecreatefromwebp($this->image_source); |
|
155
|
|
|
$this->image_type = 'webp'; |
|
156
|
|
|
break; |
|
157
|
|
|
case '.gif': |
|
158
|
|
|
$this->image = imagecreatefromgif($this->image_source); |
|
159
|
|
|
$this->image_type = 'gif'; |
|
160
|
|
|
break; |
|
161
|
|
|
default: |
|
162
|
|
|
$this->image = imagecreatefromjpeg($this->image_source); |
|
163
|
|
|
$this->image_type = 'jpeg'; |
|
164
|
|
|
break; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
$file_size = 0; |
|
168
|
|
|
if (isset($this->image_size['file'])) |
|
169
|
|
|
{ |
|
170
|
|
|
$file_size = $this->image_size['file']; |
|
171
|
|
|
} |
|
172
|
|
|
else if ($force_filesize) |
|
173
|
|
|
{ |
|
174
|
|
|
$file_size = @filesize($this->image_source); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
$image_size = getimagesize($this->image_source); |
|
178
|
|
|
|
|
179
|
|
|
$this->image_size['file'] = $file_size; |
|
180
|
|
|
$this->image_size['width'] = $image_size[0]; |
|
181
|
|
|
$this->image_size['height'] = $image_size[1]; |
|
182
|
|
|
|
|
183
|
|
|
$this->image_content_type = $image_size['mime']; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Write image to disk |
|
188
|
|
|
* @param $destination |
|
189
|
|
|
* @param int $quality |
|
190
|
|
|
* @param bool $destroy_image |
|
191
|
|
|
*/ |
|
192
|
|
|
public function write_image($destination, $quality = -1, $destroy_image = false) |
|
193
|
|
|
{ |
|
194
|
|
|
if ($quality == -1) |
|
195
|
|
|
{ |
|
196
|
|
|
$quality = $this->gallery_config->get('jpg_quality'); |
|
197
|
|
|
} |
|
198
|
|
|
switch ($this->image_type) |
|
199
|
|
|
{ |
|
200
|
|
|
case 'jpeg': |
|
201
|
|
|
imagejpeg($this->image, $destination, $quality); |
|
202
|
|
|
break; |
|
203
|
|
|
case 'png': |
|
204
|
|
|
imagepng($this->image, $destination); |
|
205
|
|
|
break; |
|
206
|
|
|
case 'webp': |
|
207
|
|
|
imagewebp($this->image, $destination); |
|
208
|
|
|
break; |
|
209
|
|
|
case 'gif': |
|
210
|
|
|
imagegif($this->image, $destination); |
|
211
|
|
|
break; |
|
212
|
|
|
} |
|
213
|
|
|
@chmod($destination, $this->chmod); |
|
|
|
|
|
|
214
|
|
|
|
|
215
|
|
|
if ($destroy_image) |
|
216
|
|
|
{ |
|
217
|
|
|
imagedestroy($this->image); |
|
218
|
|
|
} |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* Get a browser friendly UTF-8 encoded filename |
|
223
|
|
|
* |
|
224
|
|
|
* @param $file |
|
225
|
|
|
* @return string |
|
226
|
|
|
*/ |
|
227
|
|
|
public function header_filename($file) |
|
228
|
|
|
{ |
|
229
|
|
|
$raw = $this->request->server('HTTP_USER_AGENT'); |
|
230
|
|
|
$user_agent = htmlspecialchars($raw); |
|
231
|
|
|
|
|
232
|
|
|
// There be dragons here. |
|
233
|
|
|
// Not many follows the RFC... |
|
234
|
|
|
if (strpos($user_agent, 'MSIE') !== false || strpos($user_agent, 'Safari') !== false || strpos($user_agent, 'Konqueror') !== false) |
|
235
|
|
|
{ |
|
236
|
|
|
return "filename=" . rawurlencode($file); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
// follow the RFC for extended filename for the rest |
|
240
|
|
|
return "filename*=UTF-8''" . rawurlencode($file); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* We need to disable the "last-modified" caching for guests and in cases of image-errors, |
|
245
|
|
|
* so that they can view them, if they logged in or the error was fixed. |
|
246
|
|
|
*/ |
|
247
|
|
|
public function disable_browser_cache() |
|
248
|
|
|
{ |
|
249
|
|
|
$this->browser_cache = false; |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
/** |
|
253
|
|
|
* Collect the last timestamp where something changed. |
|
254
|
|
|
* This must contain: |
|
255
|
|
|
* - Last change of the file |
|
256
|
|
|
* - Last change of user's permissions |
|
257
|
|
|
* - Last change of user's groups |
|
258
|
|
|
* - Last change of watermark config |
|
259
|
|
|
* - Last change of watermark file |
|
260
|
|
|
* @param $timestamp |
|
261
|
|
|
*/ |
|
262
|
|
|
public function set_last_modified($timestamp) |
|
263
|
|
|
{ |
|
264
|
|
|
$this->last_modified = max($timestamp, $this->last_modified); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
static public function is_ie_greater7($browser) |
|
268
|
|
|
{ |
|
269
|
|
|
return (bool) preg_match('/msie (\d{2,3}|[89]+).[0-9.]*;/', strtolower($browser)); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
public function create_thumbnail($max_width, $max_height, $print_details = false, $additional_height = 0, $image_size = array()) |
|
273
|
|
|
{ |
|
274
|
|
|
$this->resize_image($max_width, $max_height, (($print_details) ? $additional_height : 0)); |
|
275
|
|
|
|
|
276
|
|
|
// Create image details credits to Dr.Death |
|
277
|
|
|
if ($print_details && sizeof($image_size)) |
|
278
|
|
|
{ |
|
279
|
|
|
$dimension_font = 1; |
|
280
|
|
|
$dimension_string = $image_size['width'] . "x" . $image_size['height'] . "(" . intval($image_size['file'] / 1024) . "KiB)"; |
|
281
|
|
|
$dimension_colour = imagecolorallocate($this->image, 255, 255, 255); |
|
282
|
|
|
$dimension_height = imagefontheight($dimension_font); |
|
283
|
|
|
$dimension_width = imagefontwidth($dimension_font) * strlen($dimension_string); |
|
284
|
|
|
$dimension_x = ($this->image_size['width'] - $dimension_width) / 2; |
|
285
|
|
|
$dimension_y = $this->image_size['height'] + (($additional_height - $dimension_height) / 2); |
|
286
|
|
|
$black_background = imagecolorallocate($this->image, 0, 0, 0); |
|
287
|
|
|
imagefilledrectangle($this->image, 0, $this->thumb_height, $this->thumb_width, $this->thumb_height + $additional_height, $black_background); |
|
288
|
|
|
imagestring($this->image, 1, $dimension_x, $dimension_y, $dimension_string, $dimension_colour); |
|
289
|
|
|
} |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
public function resize_image($max_width, $max_height, $additional_height = 0) |
|
293
|
|
|
{ |
|
294
|
|
|
if (!$this->image) |
|
295
|
|
|
{ |
|
296
|
|
|
$this->read_image(); |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
if (($this->image_size['height'] <= $max_height) && ($this->image_size['width'] <= $max_width)) |
|
300
|
|
|
{ |
|
301
|
|
|
// image is small enough, nothing to do here. |
|
302
|
|
|
return; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
if (($this->image_size['height'] / $max_height) > ($this->image_size['width'] / $max_width)) |
|
306
|
|
|
{ |
|
307
|
|
|
$this->thumb_height = $max_height; |
|
308
|
|
|
$this->thumb_width = round($max_width * (($this->image_size['width'] / $max_width) / ($this->image_size['height'] / $max_height))); |
|
309
|
|
|
} |
|
310
|
|
|
else |
|
311
|
|
|
{ |
|
312
|
|
|
$this->thumb_height = round($max_height * (($this->image_size['height'] / $max_height) / ($this->image_size['width'] / $max_width))); |
|
313
|
|
|
$this->thumb_width = $max_width; |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
$image_copy = (($this->gd_version == self::GDLIB1) ? @imagecreate($this->thumb_width, $this->thumb_height + $additional_height) : @imagecreatetruecolor($this->thumb_width, $this->thumb_height + $additional_height)); |
|
317
|
|
|
if ($this->image_type != 'jpeg') |
|
318
|
|
|
{ |
|
319
|
|
|
imagealphablending($image_copy, false); |
|
|
|
|
|
|
320
|
|
|
imagesavealpha($image_copy, true); |
|
|
|
|
|
|
321
|
|
|
$transparent = imagecolorallocatealpha($image_copy, 255, 255, 255, 127); |
|
|
|
|
|
|
322
|
|
|
imagefilledrectangle($image_copy, 0, 0, $this->thumb_width, $this->thumb_height + $additional_height, $transparent); |
|
|
|
|
|
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
$resize_function = ($this->gd_version == self::GDLIB1) ? 'imagecopyresized' : 'imagecopyresampled'; |
|
326
|
|
|
$resize_function($image_copy, $this->image, 0, 0, 0, 0, $this->thumb_width, $this->thumb_height, $this->image_size['width'], $this->image_size['height']); |
|
327
|
|
|
|
|
328
|
|
|
imagealphablending($image_copy, true); |
|
329
|
|
|
imagesavealpha($image_copy, true); |
|
330
|
|
|
$this->image = $image_copy; |
|
331
|
|
|
|
|
332
|
|
|
$this->image_size['height'] = $this->thumb_height; |
|
333
|
|
|
$this->image_size['width'] = $this->thumb_width; |
|
334
|
|
|
|
|
335
|
|
|
$this->resized = true; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* Rotate the image |
|
340
|
|
|
* Usage optimized for 0�, 90�, 180� and 270� because of the height and width |
|
341
|
|
|
* |
|
342
|
|
|
* @param $angle |
|
343
|
|
|
* @param $ignore_dimensions |
|
344
|
|
|
*/ |
|
345
|
|
|
public function rotate_image($angle, $ignore_dimensions) |
|
346
|
|
|
{ |
|
347
|
|
|
if (!function_exists('imagerotate')) |
|
348
|
|
|
{ |
|
349
|
|
|
$this->errors[] = array('ROTATE_IMAGE_FUNCTION', $angle); |
|
350
|
|
|
return; |
|
351
|
|
|
} |
|
352
|
|
|
if (($angle <= 0) || (($angle % 90) != 0)) |
|
353
|
|
|
{ |
|
354
|
|
|
$this->errors[] = array('ROTATE_IMAGE_ANGLE', $angle); |
|
355
|
|
|
return; |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
if (!$this->image) |
|
359
|
|
|
{ |
|
360
|
|
|
$this->read_image(); |
|
361
|
|
|
} |
|
362
|
|
|
if ((($angle / 90) % 2) == 1) |
|
363
|
|
|
{ |
|
364
|
|
|
// Left or Right, we need to switch the height and width |
|
365
|
|
|
if (!$ignore_dimensions && (($this->image_size['height'] > $this->max_width) || ($this->image_size['width'] > $this->max_height))) |
|
366
|
|
|
{ |
|
367
|
|
|
// image would be to wide/high |
|
368
|
|
|
if ($this->image_size['height'] > $this->max_width) |
|
369
|
|
|
{ |
|
370
|
|
|
$this->errors[] = array('ROTATE_IMAGE_WIDTH'); |
|
371
|
|
|
} |
|
372
|
|
|
if ($this->image_size['width'] > $this->max_height) |
|
373
|
|
|
{ |
|
374
|
|
|
$this->errors[] = array('ROTATE_IMAGE_HEIGHT'); |
|
375
|
|
|
} |
|
376
|
|
|
return; |
|
377
|
|
|
} |
|
378
|
|
|
$new_width = $this->image_size['height']; |
|
379
|
|
|
$this->image_size['height'] = $this->image_size['width']; |
|
380
|
|
|
$this->image_size['width'] = $new_width; |
|
381
|
|
|
} |
|
382
|
|
|
$this->image = imagerotate($this->image, $angle, 0); |
|
383
|
|
|
|
|
384
|
|
|
$this->rotated = true; |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
/** |
|
388
|
|
|
* Watermark the image: |
|
389
|
|
|
* |
|
390
|
|
|
* @param $watermark_source |
|
391
|
|
|
* @param int $watermark_position summary of the parameters for vertical and horizontal adjustment |
|
392
|
|
|
* @param int $min_height |
|
393
|
|
|
* @param int $min_width |
|
394
|
|
|
*/ |
|
395
|
|
|
public function watermark_image($watermark_source, $watermark_position = 20, $min_height = 0, $min_width = 0) |
|
396
|
|
|
{ |
|
397
|
|
|
$this->watermark_source = $watermark_source; |
|
398
|
|
|
if (!$this->watermark_source || !file_exists($this->watermark_source)) |
|
399
|
|
|
{ |
|
400
|
|
|
$this->errors[] = array('WATERMARK_IMAGE_SOURCE'); |
|
401
|
|
|
return; |
|
402
|
|
|
} |
|
403
|
|
|
|
|
404
|
|
|
if (!$this->image) |
|
405
|
|
|
{ |
|
406
|
|
|
$this->read_image(); |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
if (($min_height && ($this->image_size['height'] < $min_height)) || ($min_width && ($this->image_size['width'] < $min_width))) |
|
410
|
|
|
{ |
|
411
|
|
|
return; |
|
412
|
|
|
//$this->errors[] = array('WATERMARK_IMAGE_DIMENSION'); |
|
413
|
|
|
} |
|
414
|
|
|
$get_dot = strrpos($this->image_source, '.'); |
|
415
|
|
|
$get_wm_name = substr_replace($this->image_source, '_wm', $get_dot, 0); |
|
416
|
|
|
if (file_exists($get_wm_name)) |
|
|
|
|
|
|
417
|
|
|
{ |
|
418
|
|
|
$this->image_source = $get_wm_name; |
|
419
|
|
|
$this->read_image(); |
|
420
|
|
|
} |
|
421
|
|
|
else |
|
422
|
|
|
{ |
|
423
|
|
|
$this->watermark_size = getimagesize($this->watermark_source); |
|
424
|
|
|
switch ($this->watermark_size['mime']) |
|
425
|
|
|
{ |
|
426
|
|
|
case 'image/png': |
|
427
|
|
|
$imagecreate = 'imagecreatefrompng'; |
|
428
|
|
|
break; |
|
429
|
|
|
case 'image/webp': |
|
430
|
|
|
$imagecreate = 'imagecreatefromwebp'; |
|
431
|
|
|
break; |
|
432
|
|
|
case 'image/gif': |
|
433
|
|
|
$imagecreate = 'imagecreatefromgif'; |
|
434
|
|
|
break; |
|
435
|
|
|
default: |
|
436
|
|
|
$imagecreate = 'imagecreatefromjpeg'; |
|
437
|
|
|
break; |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
// Get the watermark as resource. |
|
441
|
|
|
if (($this->watermark = $imagecreate($this->watermark_source)) === false) |
|
442
|
|
|
{ |
|
443
|
|
|
$this->errors[] = array('WATERMARK_IMAGE_IMAGECREATE'); |
|
444
|
|
|
} |
|
445
|
|
|
|
|
446
|
|
|
$phpbb_gallery_constants = new \phpbbgallery\core\constants(); |
|
447
|
|
|
// Where do we display the watermark? up-left, down-right, ...? |
|
448
|
|
|
$dst_x = (($this->image_size['width'] * 0.5) - ($this->watermark_size[0] * 0.5)); |
|
449
|
|
|
$dst_y = ($this->image_size['height'] - $this->watermark_size[1] - 5); |
|
450
|
|
|
if ($watermark_position & $phpbb_gallery_constants::WATERMARK_LEFT) |
|
451
|
|
|
{ |
|
452
|
|
|
$dst_x = 5; |
|
453
|
|
|
} |
|
454
|
|
|
else if ($watermark_position & $phpbb_gallery_constants::WATERMARK_RIGHT) |
|
455
|
|
|
{ |
|
456
|
|
|
$dst_x = ($this->image_size['width'] - $this->watermark_size[0] - 5); |
|
457
|
|
|
} |
|
458
|
|
|
if ($watermark_position & $phpbb_gallery_constants::WATERMARK_TOP) |
|
459
|
|
|
{ |
|
460
|
|
|
$dst_y = 5; |
|
461
|
|
|
} |
|
462
|
|
|
else if ($watermark_position & $phpbb_gallery_constants::WATERMARK_MIDDLE) |
|
463
|
|
|
{ |
|
464
|
|
|
$dst_y = (($this->image_size['height'] * 0.5) - ($this->watermark_size[1] * 0.5)); |
|
465
|
|
|
} |
|
466
|
|
|
imagecopy($this->image, $this->watermark, $dst_x, $dst_y, 0, 0, $this->watermark_size[0], $this->watermark_size[1]); |
|
|
|
|
|
|
467
|
|
|
imagedestroy($this->watermark); |
|
468
|
|
|
$this->write_image($get_wm_name); |
|
469
|
|
|
$this->image_source = $get_wm_name; |
|
470
|
|
|
$this->read_image(); |
|
471
|
|
|
} |
|
472
|
|
|
$this->watermarked = true; |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
/** |
|
476
|
|
|
* Delete file from disc. |
|
477
|
|
|
* |
|
478
|
|
|
* @param mixed $files String with filename or an array of filenames |
|
479
|
|
|
* Array-Format: $image_id => $filename |
|
480
|
|
|
* @param array $locations Array of valid url::path()s where the image should be deleted from |
|
481
|
|
|
*/ |
|
482
|
|
|
public function delete($files, $locations = array('thumbnail', 'medium', 'upload')) |
|
483
|
|
|
{ |
|
484
|
|
|
if (!is_array($files)) |
|
485
|
|
|
{ |
|
486
|
|
|
$files = array(1 => $files); |
|
487
|
|
|
} |
|
488
|
|
|
// Let's delete watermarked |
|
489
|
|
|
$this->delete_wm($files); |
|
490
|
|
|
foreach ($files as $image_id => $file) |
|
491
|
|
|
{ |
|
492
|
|
|
foreach ($locations as $location) |
|
493
|
|
|
{ |
|
494
|
|
|
@unlink($this->url->path($location) . $file); |
|
|
|
|
|
|
495
|
|
|
} |
|
496
|
|
|
} |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
/** |
|
500
|
|
|
* @param $files |
|
501
|
|
|
* @param array $locations |
|
502
|
|
|
*/ |
|
503
|
|
|
public function delete_cache($files, $locations = array('thumbnail', 'medium')) |
|
504
|
|
|
{ |
|
505
|
|
|
if (!is_array($files)) |
|
506
|
|
|
{ |
|
507
|
|
|
$files = array(1 => $files); |
|
508
|
|
|
} |
|
509
|
|
|
$this->delete_wm($files); |
|
510
|
|
|
foreach ($files as $image_id => $file) |
|
511
|
|
|
{ |
|
512
|
|
|
foreach ($locations as $location) |
|
513
|
|
|
{ |
|
514
|
|
|
@unlink($this->url->path($location) . $file); |
|
|
|
|
|
|
515
|
|
|
} |
|
516
|
|
|
} |
|
517
|
|
|
} |
|
518
|
|
|
|
|
519
|
|
|
/** |
|
520
|
|
|
* @param $files |
|
521
|
|
|
*/ |
|
522
|
|
|
public function delete_wm($files) |
|
523
|
|
|
{ |
|
524
|
|
|
$locations = array('upload', 'medium'); |
|
525
|
|
|
if (!is_array($files)) |
|
526
|
|
|
{ |
|
527
|
|
|
$files = array(1 => $files); |
|
528
|
|
|
} |
|
529
|
|
|
foreach ($files as $image_id => $file) |
|
530
|
|
|
{ |
|
531
|
|
|
$get_dot = strrpos($file, '.'); |
|
532
|
|
|
$get_wm_name = substr_replace($file, '_wm', $get_dot, 0); |
|
533
|
|
|
foreach ($locations as $location) |
|
534
|
|
|
{ |
|
535
|
|
|
@unlink($this->url->path($location) . $get_wm_name); |
|
|
|
|
|
|
536
|
|
|
} |
|
537
|
|
|
} |
|
538
|
|
|
} |
|
539
|
|
|
} |
|
540
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths