diff --git a/conf/app.php b/conf/app.php
index 28e428d..6af62d1 100644
--- a/conf/app.php
+++ b/conf/app.php
@@ -3,7 +3,7 @@
* Config
*/
$configs = array(
- 'version' => '0.3.1',
+ 'version' => '0.3.2',
'releaseDate' => '2024-9-28',
'showVersion' => false, //默认不显示版本号和发布日期
@@ -58,7 +58,15 @@ $configs = array(
'screenshot_start' => 1000, //视频播放页快照截取开始时间,单位:毫秒
'screenshot_expire_seconds' => 315360000, //视频封面图缓存3650天
- 'small_image_zoom_rate' => 2.5, //缩略图在最小尺寸基础上的放大倍数,以确保清晰度
+ 'small_image_zoom_rate' => 2.5, //浏览器生成缩略图在其展示尺寸的放大倍数,以确保清晰度
+
+ //列表页缩略图尺寸设置
+ 'small_image_min_width' => 360, //缩略图最小宽度设置,以确保清晰度
+ 'small_image_min_height' => 270, //缩略图最小高度设置,以确保清晰度
+
+ //预览大图时,缩略图尺寸设置
+ 'middle_image_min_width' => 1080, //打开图片浏览器显示大图时,大图的最小宽度设置,以确保清晰度
+ 'middle_image_min_height' => 720, //打开图片浏览器显示大图时,大图的最小高度设置,以确保清晰度
'enableSmallImage' => true, //列表页面是否开启缩略图,true 为显示缩略图,false 则显示原图
'enableSmallImageForWan' => false, //外网使用时,点击图片打开fancybox时是否显示缩略图:true 显示缩略图, false 则显示原图
diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php
index 967ad0b..cfaa48e 100644
--- a/themes/beauty/controller/SiteController.php
+++ b/themes/beauty/controller/SiteController.php
@@ -401,7 +401,7 @@ Class SiteController extends Controller {
//小尺寸图片支持
if (!empty(FSC::$app['config']['enableSmallImage']) && FSC::$app['config']['enableSmallImage'] !== 'false') {
- $cacheKey_smimg = $this->getCacheKey($imgFile['id'], 'imgsm');
+ $cacheKey_smimg = $this->getCacheKey("{$imgFile['id']}_small", 'imgsm');
$expireSeconds = FSC::$app['config']['screenshot_expire_seconds']; //有效期3650天
$cacheSubDir = 'image';
$cachedData = Common::getCacheFromFile($cacheKey_smimg, $expireSeconds, $cacheSubDir);
@@ -415,10 +415,12 @@ Class SiteController extends Controller {
}else {
//实时生成缩略图
$img_filepath = $imgFile['realpath'];
- $img_data = $this->createSmallJpg($img_filepath);
+ $imgSize = 'small';
+ $sizeOptions = $this->getImageSizeOptions($imgSize);
+ $img_data = $this->createSmallJpg($img_filepath, $sizeOptions['min_width'], $sizeOptions['min_height']);
if (!empty($img_data)) {
//保存到缓存文件
- $cacheKey_smimg = $this->getCacheKey($imgFile['id'], 'imgsm');
+ $cacheKey_smimg = $this->getCacheKey("{$imgFile['id']}_small", 'imgsm');
$cacheSubDir = 'image';
$base64_img = base64_encode($img_data);
Common::saveCacheToFile($cacheKey_smimg, "data:image/jpeg;base64,{$base64_img}", $cacheSubDir);
@@ -482,7 +484,7 @@ Class SiteController extends Controller {
}
//借助gd库,获取图片类型、尺寸,并实时生成缩略图
- protected function createSmallJpg($img_filepath, $min_width = 198, $min_height = 219, $max_width = 600, $max_height = 500) {
+ protected function createSmallJpg($img_filepath, $min_width = 100, $min_height = 100) {
//如果服务器端生成缩略图关闭
if (!empty(FSC::$app['config']['disableGenerateSmallImageInServer']) && FSC::$app['config']['disableGenerateSmallImageInServer'] !== 'false') {
return false;
@@ -495,22 +497,17 @@ Class SiteController extends Controller {
$imgType = image_type_to_extension($imgTypeIndex);
//小图片则保持原图尺寸
- if ($naturalWidth <= $max_width || $naturalHeight <= $max_height) {
+ if ($naturalWidth <= $min_width || $naturalHeight <= $min_height) {
return false;
}
//生成同比例缩略图尺寸
- $zoomRate = FSC::$app['config']['small_image_zoom_rate']; //缩略图在最小尺寸基础上放大比例,为确保清晰度
$width = $min_width;
$height = $min_height;
$aspect = $naturalHeight / $naturalWidth;
if ($naturalWidth <= $naturalHeight) {
- if ($width * $zoomRate >= $naturalWidth) {return false;} //避免把小图片放大
- $width = $width * $zoomRate <= $max_width ? (int)($width * $zoomRate) : $max_width;
$height = (int)($width * $aspect);
}else {
- if ($height * $zoomRate >= $naturalHeight) {return false;} //避免把小图片放大
- $height = $height * $zoomRate <= $max_height ? (int)($height * $zoomRate) : $max_height;
$width = (int)($height / $aspect);
}
@@ -558,16 +555,35 @@ Class SiteController extends Controller {
return $img_data;
}
+ //根据图片大小类型获取最大、最小尺寸设置
+ protected function getImageSizeOptions($imgSize) {
+ $options = array(
+ 'min_width' => FSC::$app['config']['small_image_min_width'],
+ 'min_height' => FSC::$app['config']['small_image_min_height'],
+ );
+
+ if ($imgSize == 'middle') {
+ $options = array(
+ 'min_width' => FSC::$app['config']['middle_image_min_width'],
+ 'min_height' => FSC::$app['config']['middle_image_min_height'],
+ );
+ }
+
+ return $options;
+ }
+
//优先从缓存获取小尺寸的图片
//增加父目录封面图缓存更新
+ //增加图片尺寸类型参数: size
public function actionSmallimg() {
$imgId = $this->get('id', '');
$imgUrl = $this->get('url', '');
+ $imgSize = $this->get('size', 'small');
if (empty($imgId) || empty($imgUrl)) {
return $this->redirect('/img/beauty/lazy.svg');
}
- $cacheKey = $this->getCacheKey($imgId, 'imgsm');
+ $cacheKey = $this->getCacheKey("{$imgId}_{$imgSize}", 'imgsm');
$expireSeconds = FSC::$app['config']['screenshot_expire_seconds']; //有效期3650天
$cacheSubDir = 'image';
$cachedData = Common::getCacheFromFile($cacheKey, $expireSeconds, $cacheSubDir);
@@ -576,10 +592,10 @@ Class SiteController extends Controller {
if (empty($cachedData)) {
$tmpUrl = parse_url($imgUrl);
$img_filepath = __DIR__ . '/../../../www' . $tmpUrl['path'];
- $img_data = $this->createSmallJpg($img_filepath);
+ $sizeOptions = $this->getImageSizeOptions($imgSize);
+ $img_data = $this->createSmallJpg($img_filepath, $sizeOptions['min_width'], $sizeOptions['min_height']);
if (!empty($img_data)) {
//保存到缓存文件
- $cacheKey = $this->getCacheKey($imgId, 'imgsm');
$cacheSubDir = 'image';
$base64_img = base64_encode($img_data);
Common::saveCacheToFile($cacheKey, "data:image/jpeg;base64,{$base64_img}", $cacheSubDir);
@@ -627,7 +643,8 @@ Class SiteController extends Controller {
Common::saveCacheToFile($cacheKey, array('url' => $imgData, 'img_id' => $img_id, 'size' => $size), $cacheSubDir);
}
- $cacheKey = $this->getCacheKey($imgId, 'imgsm');
+ $imgSize = 'small';
+ $cacheKey = $this->getCacheKey("{$imgId}_{$imgSize}", 'imgsm');
$cacheSubDir = 'image';
$saved = Common::saveCacheToFile($cacheKey, $imgData, $cacheSubDir);
diff --git a/themes/beauty/views/layout/main.php b/themes/beauty/views/layout/main.php
index 7c048e5..d34e5c2 100644
--- a/themes/beauty/views/layout/main.php
+++ b/themes/beauty/views/layout/main.php
@@ -104,6 +104,16 @@ require_once __DIR__ . '/../../../../plugins/Html.php';
+
@@ -112,13 +122,6 @@ require_once __DIR__ . '/../../../../plugins/Html.php';
-