Auto commit: 2025-12-18T02:31:04.349Z
This commit is contained in:
parent
b2a5953ed8
commit
eff072b3ce
BIN
assets/images/uploads/thumbnail_69436287a48d7.jpg
Normal file
BIN
assets/images/uploads/thumbnail_69436287a48d7.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 63 KiB |
@ -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) {
|
||||
|
||||
@ -141,7 +141,7 @@ $current_links = $link_stmt->fetchAll();
|
||||
}
|
||||
?>
|
||||
<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-title">
|
||||
<a href="<?php echo htmlspecialchars($link['url']); ?>" target="_blank" rel="noopener noreferrer">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user