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";
17 if (!file_exists($target)) {
19 mkthumb($imgpath, $target, $width, $height);
21 catch (Exception $e) {
22 http_response_code($e->getCode() ?: 500);
24 if (file_exists($target)) {
25 header("X-Error: ".$e->getMessage());
26 header('Content-type: '.mime_content_type($target));
30 trigger_error("thumbnail creation failed: ".$e->getMessage(), E_USER_WARNING);
35 header('Content-type: '.mime_content_type($target));
39 function mkthumb($source, $target, $width, $height)
41 @mkdir(dirname($target), 0777, TRUE);
42 return mkthumb_exec($source, $target, $width, $height);
45 function mkthumb_exec($source, $target, $width, $height)
47 if (!function_exists('popen')) {
48 throw new Exception("exec disallowed on this server", 501);
50 $cmd = implode(' ', array_map('escapeshellarg', [
53 '-resize', "${width}x${height}",
57 $return = shell_exec("$cmd 2>&1");
59 throw new Exception($return);