XOOPS  2.6.0
thumbrender.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  */
11 
13 
21 // this is located in include, otherwise normal/anon users do not have authority to run
22 include dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
23 
24 $xoops = Xoops::getinstance();
25 $xoops->logger()->quiet();
26 
27 $imgPath = Request::getString('img', '');
28 $imgWidth = Request::getInt('w', 0);
29 $imgHeight = Request::getInt('h', 0);
30 
31 if ($imgWidth==0 && $imgHeight==0) {
32  $configs = $xoops->getModuleConfigs('thumbs');
33  $imgWidth = $configs['thumbs_width'];
34  $imgHeight = $configs['thumbs_height'];
35 }
36 $helper = $xoops->getModuleHelper('thumbs');
38 
39 $oldUmask = umask(022);
40 mkdir(dirname($xoops->path($thumbPath)), 0755, true);
41 umask($oldUmask);
42 
43 $image = new Zebra_Image();
44 
45 $image->source_path = $xoops->path($imgPath);
46 $image->target_path = $xoops->path($thumbPath);
47 
48 $image->preserve_aspect_ratio = true;
49 $image->enlarge_smaller_images = false;
50 $image->preserve_time = true;
51 
52 if ($image->resize($imgWidth, $imgHeight, ZEBRA_IMAGE_NOT_BOXED, -1)) {
53  header("HTTP/1.1 301 Moved Permanently");
54  header('Location: ' . $xoops->url($thumbPath));
55 } else {
56  header("HTTP/1.0 404 Not Found");
57  // http_response_code(400);
58  // exit("Parameter error");
59  switch ($image->error) {
60  case 1:
61  echo 'Source file could not be found!';
62  break;
63  case 2:
64  echo 'Source file is not readable!';
65  break;
66  case 3:
67  echo 'Could not write target file!';
68  break;
69  case 4:
70  echo 'Unsupported source file format!';
71  break;
72  case 5:
73  echo 'Unsupported target file format!';
74  break;
75  case 6:
76  echo 'GD library version does not support target file format!';
77  break;
78  case 7:
79  echo 'GD library is not installed!';
80  break;
81  case 8:
82  echo '"chmod" command is disabled via configuration!';
83  break;
84  }
85 }
86 exit();
$imgWidth
Definition: thumbrender.php:28
$imgPath
Definition: thumbrender.php:27
exit
Definition: browse.php:104
$oldUmask
Definition: thumbrender.php:39
$thumbPath
Definition: thumbrender.php:37
if($imgWidth==0 &&$imgHeight==0) $helper
Definition: thumbrender.php:36
$configs
Definition: config.php:27
$xoops
Definition: thumbrender.php:24
$imgHeight
Definition: thumbrender.php:29
$image
Definition: thumbrender.php:43