diff --git a/assets/images/uploads/thumbnail_69436287a48d7.jpg b/assets/images/uploads/thumbnail_69436287a48d7.jpg new file mode 100644 index 0000000..f6242f2 Binary files /dev/null and b/assets/images/uploads/thumbnail_69436287a48d7.jpg differ diff --git a/includes/ImageProcessor.php b/includes/ImageProcessor.php index 4048336..d653b99 100644 --- a/includes/ImageProcessor.php +++ b/includes/ImageProcessor.php @@ -3,6 +3,7 @@ class ImageProcessor { private static $uploadDir = 'assets/images/uploads/'; 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. @@ -60,12 +61,37 @@ class ImageProcessor { private static function resizeImage(string $imagePath, string $mimeType) { list($width, $height) = getimagesize($imagePath); - if ($width <= self::$maxWidth) { + if ($width <= self::$maxWidth && $height <= self::$maxHeight) { return true; // No resizing needed } - $newWidth = self::$maxWidth; - $newHeight = (int) (self::$maxWidth * ($height / $width)); + $aspectRatio = $width / $height; + $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; switch ($mimeType) { diff --git a/index.php b/index.php index 13dec30..8ad6563 100644 --- a/index.php +++ b/index.php @@ -141,7 +141,7 @@ $current_links = $link_stmt->fetchAll(); } ?>