Auto commit: 2025-12-18T02:31:04.349Z

This commit is contained in:
Flatlogic Bot 2025-12-18 02:31:04 +00:00
parent b2a5953ed8
commit eff072b3ce
3 changed files with 30 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View File

@ -3,6 +3,7 @@
class ImageProcessor { class ImageProcessor {
private static $uploadDir = 'assets/images/uploads/'; private static $uploadDir = 'assets/images/uploads/';
private static $maxWidth = 400; // Default max width for thumbnails private static $maxWidth = 400; // Default max width for thumbnails
private static $maxHeight = 800; // Default max height for thumbnails (double the max width)
/** /**
* Handles the uploaded image, moves it to the upload directory, and resizes it. * Handles the uploaded image, moves it to the upload directory, and resizes it.
@ -60,12 +61,37 @@ class ImageProcessor {
private static function resizeImage(string $imagePath, string $mimeType) { private static function resizeImage(string $imagePath, string $mimeType) {
list($width, $height) = getimagesize($imagePath); list($width, $height) = getimagesize($imagePath);
if ($width <= self::$maxWidth) { if ($width <= self::$maxWidth && $height <= self::$maxHeight) {
return true; // No resizing needed return true; // No resizing needed
} }
$newWidth = self::$maxWidth; $aspectRatio = $width / $height;
$newHeight = (int) (self::$maxWidth * ($height / $width)); $newWidth = $width;
$newHeight = $height;
// Resize based on width if it exceeds maxWidth or if new height based on maxWidth is less than maxHeight
if ($newWidth > self::$maxWidth) {
$newWidth = self::$maxWidth;
$newHeight = (int) (self::$maxWidth / $aspectRatio);
}
// Resize based on height if it exceeds maxHeight or if new width based on maxHeight is less than maxWidth
if ($newHeight > self::$maxHeight) {
$newHeight = self::$maxHeight;
$newWidth = (int) (self::$maxHeight * $aspectRatio);
}
// Final check to ensure it fits within both dimensions after initial adjustments
if ($newWidth > self::$maxWidth) {
$newWidth = self::$maxWidth;
$newHeight = (int) (self::$maxWidth / $aspectRatio);
}
if ($newHeight > self::$maxHeight) {
$newHeight = self::$maxHeight;
$newWidth = (int) (self::$maxHeight * $aspectRatio);
}
$image = null; $image = null;
switch ($mimeType) { switch ($mimeType) {

View File

@ -141,7 +141,7 @@ $current_links = $link_stmt->fetchAll();
} }
?> ?>
<div class="link-item"> <div class="link-item">
<img src="<?php echo htmlspecialchars($link['thumbnail']); ?>" alt="Thumbnail for <?php echo htmlspecialchars($link['title']); ?>" class="thumbnail"> <img src="<?php echo htmlspecialchars($link['thumbnail_url']); ?>" alt="Thumbnail for <?php echo htmlspecialchars($link['title']); ?>" class="thumbnail">
<div class="link-item-body"> <div class="link-item-body">
<div class="link-item-title"> <div class="link-item-title">
<a href="<?php echo htmlspecialchars($link['url']); ?>" target="_blank" rel="noopener noreferrer"> <a href="<?php echo htmlspecialchars($link['url']); ?>" target="_blank" rel="noopener noreferrer">