X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/a0fbf3931f22b677a5045fb2392f6fa9714ca478..f08646f0f4d2dfe6ba6d4804e0439777c3eb8f77:/thumb/index.php diff --git a/thumb/index.php b/thumb/index.php index b49ca6e..2849bb5 100644 --- a/thumb/index.php +++ b/thumb/index.php @@ -1,34 +1,72 @@ getCode() ?: 500); + $target = '500.png'; + if (file_exists($target)) { + header("X-Error: ".$e->getMessage()); + header('Content-type: '.mime_content_type($target)); + readfile($target); + exit; + } + trigger_error("thumbnail creation failed: ".$e->getMessage(), E_USER_WARNING); exit; } -$target = preg_replace("{^data/}", "thumb/$height/", $imgpath, 1); -if (!file_exists($target)) { +header('Content-type: '.mime_content_type($target)); +readfile($target); +exit; + +function mkthumb($source, $width, $height) +{ + $target = "thumb/$height/$source"; + + if (isset($_GET['backend'])) { + $backend = $_GET['backend']; + } + elseif (file_exists($target)) { + return; + } + else { + $backend = 'exec'; + } + $backend = "mkthumb_$backend"; + @mkdir(dirname($target), 0777, TRUE); + $backend($source, $target, $width, $height); + return $target; +} +function mkthumb_exec($source, $target, $width, $height) +{ + if (!function_exists('popen')) { + throw new Exception("exec disallowed on this server", 501); + } $cmd = implode(' ', array_map('escapeshellarg', [ 'convert', '-trim', '-resize', "${width}x${height}", '-quality', '90%', - $imgpath, $target + $source, $target ])); $return = shell_exec("$cmd 2>&1"); if ($return) { - http_response_code(500); - trigger_error("thumbnail creation failed: $return", E_USER_WARNING); - exit; + throw new Exception($return); } } - -header('Content-type: '.mime_content_type($target)); -readfile($target); -exit;