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)) {
17 $target = mkthumb($imgpath, $width, $height);
19 catch (Exception $e) {
20 http_response_code($e->getCode() ?: 500);
22 if (file_exists($target)) {
23 header("X-Error: ".$e->getMessage());
24 header('Content-type: '.mime_content_type($target));
28 trigger_error("thumbnail creation failed: ".$e->getMessage(), E_USER_WARNING);
32 header('Content-type: '.mime_content_type($target));
36 function mkthumb($source, $width, $height)
38 $target = "thumb/$height/$source";
40 if (isset($_GET['backend'])) {
41 $backend = $_GET['backend'];
43 elseif (file_exists($target)) {
49 $backend = "mkthumb_$backend";
51 @mkdir(dirname($target), 0777, TRUE);
52 $backend($source, $target, $width, $height);
56 function mkthumb_exec($source, $target, $width, $height)
58 if (!function_exists('popen')) {
59 throw new Exception("exec disallowed on this server", 501);
61 $cmd = implode(' ', array_map('escapeshellarg', [
64 '-resize', "${width}x${height}",
68 $return = shell_exec("$cmd 2>&1");
70 throw new Exception($return);