4 list ($height, $imgpath) = explode('/', ltrim($Args, '/'), 2);
6 $imgpath = preg_replace('{^(?=[0-9]+/)}', 'data/', $imgpath, 1);
8 if (!file_exists($imgpath)) {
9 http_response_code(404);
11 if (!file_exists($imgpath)) {
16 $target = "thumb/$height/$imgpath";
18 mkthumb($imgpath, $target, $width, $height);
20 catch (Exception $e) {
21 http_response_code($e->getCode() ?: 500);
23 if (file_exists($target)) {
24 header("X-Error: ".$e->getMessage());
25 header('Content-type: '.mime_content_type($target));
29 trigger_error("thumbnail creation failed: ".$e->getMessage(), E_USER_WARNING);
33 header('Content-type: '.mime_content_type($target));
37 function mkthumb($source, $target, $width, $height)
39 if (isset($_GET['backend'])) {
40 $backend = $_GET['backend'];
42 elseif (file_exists($target)) {
48 $backend = "mkthumb_$backend";
50 @mkdir(dirname($target), 0777, TRUE);
51 $backend($source, $target, $width, $height);
54 function mkthumb_exec($source, $target, $width, $height)
56 if (!function_exists('popen')) {
57 throw new Exception("exec disallowed on this server", 501);
59 $cmd = implode(' ', array_map('escapeshellarg', [
62 '-resize', "${width}x${height}",
66 $return = shell_exec("$cmd 2>&1");
68 throw new Exception($return);