4 list ($height, $imgpath) = explode('/', ltrim($Args, '/'), 2);
6 $imgpath = preg_replace('{^(?=[0-9]+/)}', 'data/', $imgpath, 1);
8 if (!function_exists('popen')) {
9 http_response_code(501);
11 header('Content-type: '.mime_content_type($target));
16 if (!file_exists($imgpath)) {
17 http_response_code(404);
21 $target = "thumb/$height/$imgpath";
22 if (!file_exists($target)) {
24 mkthumb($imgpath, $target, $width, $height);
26 catch (Exception $e) {
27 http_response_code(500);
28 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 @mkdir(dirname($target), 0777, TRUE);
40 return mkthumb_exec($source, $target, $width, $height);
43 function mkthumb_exec($source, $target, $width, $height)
45 $cmd = implode(' ', array_map('escapeshellarg', [
48 '-resize', "${width}x${height}",
52 $return = shell_exec("$cmd 2>&1");
54 throw new Exception($return);