+ try {
+ mkthumb($imgpath, $target, $width, $height);
+ }
+ catch (Exception $e) {
+ http_response_code(500);
+ trigger_error("thumbnail creation failed: ".$e->getMessage(), E_USER_WARNING);
+ exit;
+ }
+}
+
+header('Content-type: '.mime_content_type($target));
+readfile($target);
+exit;
+
+function mkthumb($source, $target, $width, $height)
+{