From 1dc8527695b47ac060fcdbfdff9b9079b9882158 Mon Sep 17 00:00:00 2001 From: filesite Date: Mon, 12 Aug 2024 12:29:44 +0800 Subject: [PATCH] create snapshot image for dirs --- themes/beauty/controller/SiteController.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index 0868e25..03b6d90 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -317,6 +317,24 @@ Class SiteController extends Controller { //当前目录有缩略图的时候才缓存 $cacheSubDir = 'dir'; Common::saveCacheToFile($cacheKey, compact('url', 'size'), $cacheSubDir); + }else { + //实时生成缩略图 + $img_filepath = $imgFile['realpath']; + $img_data = $this->createSmallJpg($img_filepath); + if (!empty($img_data)) { + //保存到缓存文件 + $cacheKey_smimg = $this->getCacheKey($imgFile['id'], 'imgsm'); + $cacheSubDir = 'image'; + $base64_img = base64_encode($img_data); + Common::saveCacheToFile($cacheKey_smimg, "data:image/jpeg;base64,{$base64_img}", $cacheSubDir); + + $url = "data:image/jpeg;base64,{$base64_img}"; + $size = 'small'; + + //缓存目录封面图 + $cacheSubDir = 'dir'; + Common::saveCacheToFile($cacheKey, compact('url', 'size'), $cacheSubDir); + } } }else if (empty(FSC::$app['config']['enableSmallImage']) || FSC::$app['config']['enableSmallImage'] === 'false') { //如果关闭了缩略图功能则缓存原图