--- /dev/null
+<?php
+ob_clean();
+
+list ($height, $imgarg) = explode('/', ltrim($Args, '/'), 2);
+$width= 1000;
+$imgpath = "data/$imgarg";
+
+if (!file_exists($imgpath)) {
+ http_response_code(404);
+ exit;
+}
+
+$target = preg_replace("{^data/}", "thumb/$height/", $imgpath, 1);
+if (!file_exists($target)) {
+ @mkdir(dirname($target), 0777, TRUE);
+
+ $cmd = implode(' ', array_map('escapeshellarg', [
+ 'convert',
+ '-trim',
+ '-resize', "${width}x${height}",
+ '-quality', '90%',
+ $imgpath, $target
+ ]));
+ $return = shell_exec("$cmd 2>&1");
+ if ($return) {
+ http_response_code(500);
+ trigger_error("thumbnail creation failed: $return", E_USER_WARNING);
+ exit;
+ }
+}
+
+header('Content-type: '.mime_content_type($target));
+readfile($target);
+exit;