+ $imgpath = '404.png';
+ if (!file_exists($imgpath)) {
+ exit;
+ }
+}
+
+try {
+ $target = mkthumb($imgpath, $width, $height);
+}
+catch (Exception $e) {
+ http_response_code($e->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);