1
0
Fork 0
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:
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,31 +2458,37 @@ 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);
header("content-type: $output_mime"); // Delete the temporary image.
switch($output_mime) imagedestroy($image);
{
case "image/jpeg":
imagejpeg($preview_image);
break;
case "image/png":
imagepng($preview_image);
break;
default:
case "image/webp":
imagewebp($preview_image);
break;
}
imagedestroy($preview_image);
break; break;
default: default:
http_response_code(501); http_response_code(501);
exit("Unrecognised file type."); $preview_image = errorimage("Unrecognised file type '$mime_type'.");
} }
// Send the completed preview image to the user
header("content-type: $output_mime");
switch($output_mime)
{
case "image/jpeg":
imagejpeg($preview_image);
break;
case "image/png":
imagepng($preview_image);
break;
default:
case "image/webp":
imagewebp($preview_image);
break;
}
imagedestroy($preview_image);
}); });
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,31 +230,37 @@ 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);
header("content-type: $output_mime"); // Delete the temporary image.
switch($output_mime) imagedestroy($image);
{
case "image/jpeg":
imagejpeg($preview_image);
break;
case "image/png":
imagepng($preview_image);
break;
default:
case "image/webp":
imagewebp($preview_image);
break;
}
imagedestroy($preview_image);
break; break;
default: default:
http_response_code(501); http_response_code(501);
exit("Unrecognised file type."); $preview_image = errorimage("Unrecognised file type '$mime_type'.");
} }
// Send the completed preview image to the user
header("content-type: $output_mime");
switch($output_mime)
{
case "image/jpeg":
imagejpeg($preview_image);
break;
case "image/png":
imagepng($preview_image);
break;
default:
case "image/webp":
imagewebp($preview_image);
break;
}
imagedestroy($preview_image);
}); });
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,