1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 16:33:00 +00:00

Continue work on aspect ratio of preview images

This commit is contained in:
Starbeamrainbowlabs 2015-10-23 21:04:58 +01:00
parent 612bf0ce74
commit db81d17c5e
3 changed files with 64 additions and 15 deletions

View file

@ -1386,14 +1386,31 @@ register_module([
break;
}
$aspect_ratio = imagesx($preview) / imagesy($preview);
$raw_width = imagesx($preview);
$raw_height = imagesy($preview);
$aspect_ratio = $raw_width / $raw_height;
$target_width = intval($_GET["size"]);
if($target_width < $settings->min_preview_size)
$target_width = $settings->min_preview_size;
if($target_width > $settings->max_preview_size)
$target_width = $settings->max_preview_size;
$target_height = $target_width;
$target_size = 512;
if(isset($_GET["size"]))
$target_size = intval($_GET["size"]);
if($target_size < $settings->min_preview_size)
$target_size = $settings->min_preview_size;
if($target_size > $settings->max_preview_size)
$target_size = $settings->max_preview_size;
if($raw_width > $raw_height)
{
$preview_width = $target_size;
$preview_height = $target_size * $aspect_ratio;
}
else
{
$preview_height = $target_size;
$preview_width = $target_size * $aspect_ratio;
}
header("content-type: text/plain");
echo("raw: $raw_width x $raw_height\n");
echo("resized: $preview_width x $preview_height\n");
// Todo Scale image to fit inside size.

View file

@ -50,7 +50,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": 1445504176,
"lastupdate": 1445630469,
"optional": false
},
{

View file

@ -161,18 +161,50 @@ register_module([
break;
}
$aspect_ratio = imagesx($preview) / imagesy($preview);
$raw_width = imagesx($preview);
$raw_height = imagesy($preview);
$aspect_ratio = $raw_width / $raw_height;
$target_width = intval($_GET["size"]);
if($target_width < $settings->min_preview_size)
$target_width = $settings->min_preview_size;
if($target_width > $settings->max_preview_size)
$target_width = $settings->max_preview_size;
$target_height = $target_width;
// Determine the target size of the image
$target_size = 512;
if(isset($_GET["size"]))
$target_size = intval($_GET["size"]);
if($target_size < $settings->min_preview_size)
$target_size = $settings->min_preview_size;
if($target_size > $settings->max_preview_size)
$target_size = $settings->max_preview_size;
// Set the preview size equal to the original image dimensions
$preview_width = $raw_width;
$preview_height = $raw_height;
// If the original image doesn't fit inside the box, resize
// it's dimensions, preserving aspect ratio
if($raw_width > $target_size || $raw_height > $target_size)
{
if($raw_width > $raw_height)
{
$preview_width = $target_size;
$preview_height = $target_size * $aspect_ratio;
}
else
{
$preview_height = $target_size;
$preview_width = $target_size * $aspect_ratio;
}
}
header("content-type: text/plain");
echo("raw: $raw_width x $raw_height\n");
echo("resized: $preview_width x $preview_height\n");
// Todo Scale image to fit inside size.
break;
default:
http_response_code(501);
exit("Unrecognised file type.");
}
// todo render a preview here