X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/f08646f0f4d2dfe6ba6d4804e0439777c3eb8f77..1079aa7d6a839379e09d185e712d1ba1613686fd:/thumb/index.php diff --git a/thumb/index.php b/thumb/index.php index 2849bb5..1d36948 100644 --- a/thumb/index.php +++ b/thumb/index.php @@ -16,7 +16,7 @@ if (!file_exists($imgpath)) { try { $target = mkthumb($imgpath, $width, $height); } -catch (Exception $e) { +catch (Throwable $e) { http_response_code($e->getCode() ?: 500); $target = '500.png'; if (file_exists($target)) { @@ -43,6 +43,9 @@ function mkthumb($source, $width, $height) elseif (file_exists($target)) { return; } + elseif (extension_loaded('gd')) { + $backend = 'gd'; + } else { $backend = 'exec'; } @@ -53,6 +56,20 @@ function mkthumb($source, $width, $height) return $target; } +function mkthumb_gd($source, $target, $width, $height) +{ + $data = imagecreatefromstring(file_get_contents($source)); + if (!$data) throw new Exception("error reading $source"); + $orgwidth = imagesx($data); + $orgheight = imagesy($data); + $width = min($width, $orgwidth * $height / $orgheight); + $gd = imagecreatetruecolor($width, $height); + //TODO: trim + imagecopyresampled($gd, $data, 0, 0, 0, 0, + $width, $height, $orgwidth, $orgheight); + imagejpeg($gd, $target, 90); +} + function mkthumb_exec($source, $target, $width, $height) { if (!function_exists('popen')) {