mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-22 16:33:00 +00:00
Fix the unrecognised file type error image.
This commit is contained in:
parent
9e515e45e2
commit
53adb8bfaf
3 changed files with 51 additions and 35 deletions
|
@ -2432,9 +2432,11 @@ register_module([
|
|||
if(isset($_GET["type"]) and in_array($_GET["type"], [ "image/png", "image/jpeg", "image/webp" ]))
|
||||
$output_mime = $_GET["type"];
|
||||
|
||||
$preview_image = false;
|
||||
switch(substr($mime_type, 0, strpos($mime_type, "/")))
|
||||
{
|
||||
case "image":
|
||||
// Read in the image
|
||||
$image = false;
|
||||
switch($mime_type)
|
||||
{
|
||||
|
@ -2456,10 +2458,22 @@ register_module([
|
|||
break;
|
||||
}
|
||||
|
||||
// Get the size of the image for later
|
||||
$raw_width = imagesx($image);
|
||||
$raw_height = imagesy($image);
|
||||
|
||||
// Resize the image
|
||||
$preview_image = resize_image($image, $target_size);
|
||||
// Delete the temporary image.
|
||||
imagedestroy($image);
|
||||
break;
|
||||
|
||||
default:
|
||||
http_response_code(501);
|
||||
$preview_image = errorimage("Unrecognised file type '$mime_type'.");
|
||||
}
|
||||
|
||||
// Send the completed preview image to the user
|
||||
header("content-type: $output_mime");
|
||||
switch($output_mime)
|
||||
{
|
||||
|
@ -2475,12 +2489,6 @@ register_module([
|
|||
break;
|
||||
}
|
||||
imagedestroy($preview_image);
|
||||
break;
|
||||
|
||||
default:
|
||||
http_response_code(501);
|
||||
exit("Unrecognised file type.");
|
||||
}
|
||||
});
|
||||
|
||||
page_renderer::register_part_preprocessor(function(&$parts) {
|
||||
|
@ -2563,7 +2571,7 @@ function errorimage($text)
|
|||
$image = imagecreatetruecolor($width, $height);
|
||||
imagefill($image, 0, 0, imagecolorallocate($image, 238, 232, 242)); // Set the background to #eee8f2
|
||||
$fontwidth = imagefontwidth(3);
|
||||
imagetext($image, 3,
|
||||
imagestring($image, 3,
|
||||
($width / 2) - (($fontwidth * strlen($text)) / 2),
|
||||
($height / 2) - (imagefontheight(3) / 2),
|
||||
$text,
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
"author": "Starbeamrainbowlabs",
|
||||
"description": "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File:' prefix.",
|
||||
"id": "feature-upload",
|
||||
"lastupdate": 1459607200,
|
||||
"lastupdate": 1459621957,
|
||||
"optional": false
|
||||
},
|
||||
{
|
||||
|
|
|
@ -204,9 +204,11 @@ register_module([
|
|||
if(isset($_GET["type"]) and in_array($_GET["type"], [ "image/png", "image/jpeg", "image/webp" ]))
|
||||
$output_mime = $_GET["type"];
|
||||
|
||||
$preview_image = false;
|
||||
switch(substr($mime_type, 0, strpos($mime_type, "/")))
|
||||
{
|
||||
case "image":
|
||||
// Read in the image
|
||||
$image = false;
|
||||
switch($mime_type)
|
||||
{
|
||||
|
@ -228,10 +230,22 @@ register_module([
|
|||
break;
|
||||
}
|
||||
|
||||
// Get the size of the image for later
|
||||
$raw_width = imagesx($image);
|
||||
$raw_height = imagesy($image);
|
||||
|
||||
// Resize the image
|
||||
$preview_image = resize_image($image, $target_size);
|
||||
// Delete the temporary image.
|
||||
imagedestroy($image);
|
||||
break;
|
||||
|
||||
default:
|
||||
http_response_code(501);
|
||||
$preview_image = errorimage("Unrecognised file type '$mime_type'.");
|
||||
}
|
||||
|
||||
// Send the completed preview image to the user
|
||||
header("content-type: $output_mime");
|
||||
switch($output_mime)
|
||||
{
|
||||
|
@ -247,12 +261,6 @@ register_module([
|
|||
break;
|
||||
}
|
||||
imagedestroy($preview_image);
|
||||
break;
|
||||
|
||||
default:
|
||||
http_response_code(501);
|
||||
exit("Unrecognised file type.");
|
||||
}
|
||||
});
|
||||
|
||||
page_renderer::register_part_preprocessor(function(&$parts) {
|
||||
|
@ -335,7 +343,7 @@ function errorimage($text)
|
|||
$image = imagecreatetruecolor($width, $height);
|
||||
imagefill($image, 0, 0, imagecolorallocate($image, 238, 232, 242)); // Set the background to #eee8f2
|
||||
$fontwidth = imagefontwidth(3);
|
||||
imagetext($image, 3,
|
||||
imagestring($image, 3,
|
||||
($width / 2) - (($fontwidth * strlen($text)) / 2),
|
||||
($height / 2) - (imagefontheight(3) / 2),
|
||||
$text,
|
||||
|
|
Loading…
Reference in a new issue