1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-26 05:32:59 +00:00

Fix the unrecognised file type error image.

This commit is contained in:
Starbeamrainbowlabs 2016-04-02 19:34:01 +01:00
parent 9e515e45e2
commit 53adb8bfaf
3 changed files with 51 additions and 35 deletions

View file

@ -2432,9 +2432,11 @@ register_module([
if(isset($_GET["type"]) and in_array($_GET["type"], [ "image/png", "image/jpeg", "image/webp" ])) if(isset($_GET["type"]) and in_array($_GET["type"], [ "image/png", "image/jpeg", "image/webp" ]))
$output_mime = $_GET["type"]; $output_mime = $_GET["type"];
$preview_image = false;
switch(substr($mime_type, 0, strpos($mime_type, "/"))) switch(substr($mime_type, 0, strpos($mime_type, "/")))
{ {
case "image": case "image":
// Read in the image
$image = false; $image = false;
switch($mime_type) switch($mime_type)
{ {
@ -2456,10 +2458,22 @@ register_module([
break; break;
} }
// Get the size of the image for later
$raw_width = imagesx($image); $raw_width = imagesx($image);
$raw_height = imagesy($image); $raw_height = imagesy($image);
// Resize the image
$preview_image = resize_image($image, $target_size); $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"); header("content-type: $output_mime");
switch($output_mime) switch($output_mime)
{ {
@ -2475,12 +2489,6 @@ register_module([
break; break;
} }
imagedestroy($preview_image); imagedestroy($preview_image);
break;
default:
http_response_code(501);
exit("Unrecognised file type.");
}
}); });
page_renderer::register_part_preprocessor(function(&$parts) { page_renderer::register_part_preprocessor(function(&$parts) {
@ -2563,7 +2571,7 @@ function errorimage($text)
$image = imagecreatetruecolor($width, $height); $image = imagecreatetruecolor($width, $height);
imagefill($image, 0, 0, imagecolorallocate($image, 238, 232, 242)); // Set the background to #eee8f2 imagefill($image, 0, 0, imagecolorallocate($image, 238, 232, 242)); // Set the background to #eee8f2
$fontwidth = imagefontwidth(3); $fontwidth = imagefontwidth(3);
imagetext($image, 3, imagestring($image, 3,
($width / 2) - (($fontwidth * strlen($text)) / 2), ($width / 2) - (($fontwidth * strlen($text)) / 2),
($height / 2) - (imagefontheight(3) / 2), ($height / 2) - (imagefontheight(3) / 2),
$text, $text,

View file

@ -68,7 +68,7 @@
"author": "Starbeamrainbowlabs", "author": "Starbeamrainbowlabs",
"description": "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File:' prefix.", "description": "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File:' prefix.",
"id": "feature-upload", "id": "feature-upload",
"lastupdate": 1459607200, "lastupdate": 1459621957,
"optional": false "optional": false
}, },
{ {

View file

@ -204,9 +204,11 @@ register_module([
if(isset($_GET["type"]) and in_array($_GET["type"], [ "image/png", "image/jpeg", "image/webp" ])) if(isset($_GET["type"]) and in_array($_GET["type"], [ "image/png", "image/jpeg", "image/webp" ]))
$output_mime = $_GET["type"]; $output_mime = $_GET["type"];
$preview_image = false;
switch(substr($mime_type, 0, strpos($mime_type, "/"))) switch(substr($mime_type, 0, strpos($mime_type, "/")))
{ {
case "image": case "image":
// Read in the image
$image = false; $image = false;
switch($mime_type) switch($mime_type)
{ {
@ -228,10 +230,22 @@ register_module([
break; break;
} }
// Get the size of the image for later
$raw_width = imagesx($image); $raw_width = imagesx($image);
$raw_height = imagesy($image); $raw_height = imagesy($image);
// Resize the image
$preview_image = resize_image($image, $target_size); $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"); header("content-type: $output_mime");
switch($output_mime) switch($output_mime)
{ {
@ -247,12 +261,6 @@ register_module([
break; break;
} }
imagedestroy($preview_image); imagedestroy($preview_image);
break;
default:
http_response_code(501);
exit("Unrecognised file type.");
}
}); });
page_renderer::register_part_preprocessor(function(&$parts) { page_renderer::register_part_preprocessor(function(&$parts) {
@ -335,7 +343,7 @@ function errorimage($text)
$image = imagecreatetruecolor($width, $height); $image = imagecreatetruecolor($width, $height);
imagefill($image, 0, 0, imagecolorallocate($image, 238, 232, 242)); // Set the background to #eee8f2 imagefill($image, 0, 0, imagecolorallocate($image, 238, 232, 242)); // Set the background to #eee8f2
$fontwidth = imagefontwidth(3); $fontwidth = imagefontwidth(3);
imagetext($image, 3, imagestring($image, 3,
($width / 2) - (($fontwidth * strlen($text)) / 2), ($width / 2) - (($fontwidth * strlen($text)) / 2),
($height / 2) - (imagefontheight(3) / 2), ($height / 2) - (imagefontheight(3) / 2),
$text, $text,