From 6ae85f8ddbae19f5586f4b0c37680fe21889ef14 Mon Sep 17 00:00:00 2001
From: quanwei <419654421@qq.com>
Date: Wed, 26 Nov 2025 18:48:23 +0800
Subject: [PATCH] 修改地图key
---
admin/app/common/library/storage/engine/Local.php | 42 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/admin/app/common/library/storage/engine/Local.php b/admin/app/common/library/storage/engine/Local.php
index b05d257..e8df3b3 100644
--- a/admin/app/common/library/storage/engine/Local.php
+++ b/admin/app/common/library/storage/engine/Local.php
@@ -3,6 +3,10 @@
namespace app\common\library\storage\engine;
use think\facade\Filesystem;
+use think\Image;
+use app\common\model\settings\Setting as SettingModel;
+
+use function Qiniu\thumbnail;
/**
* 本地文件驱动
@@ -71,4 +75,42 @@
return $this->fileName;
}
+ /**
+ * 生成缩略图(将原图复制到新路径,然后将原路径变为缩略图) by lyzflash
+ */
+ public function createThumb($saveName, $is_original = false)
+ {
+ // 获取上传设置
+ $config = SettingModel::getItem('storage');
+ $image = Image::open(public_path() . '/uploads/' . $saveName);
+ $width = $image->width();
+ $max_width = $config['max_width'] ?: 750;
+ // 图片宽度大于系统设置时才处理
+ $original_path = '';
+ if ($width > $max_width) {
+ // 如果保留原图
+ if ($is_original) {
+ $original_path = date('Ymd') .'/'. $this->buildOriginalName(); // 原图文路径
+ $image->save(public_path() . '/uploads/' . $original_path);
+ }
+ // 生成缩略图
+ $image->thumb($max_width, $image->height())->save(public_path() . '/uploads/'. $saveName);
+ }
+ return $original_path; // 注意:返回的是原图的路径
+ }
+
+ /**
+ * 生成原图文件名
+ */
+ private function buildOriginalName()
+ {
+ // 要上传图片的本地路径
+ $realPath = $this->file->getPathname();
+ // 扩展名
+ $ext = $this->file->getOriginalExtension();
+ // 自动生成文件名
+ return date('YmdHis') . substr(md5($realPath), 0, 6)
+ . str_pad(rand(0, 9999), 6, '0', STR_PAD_LEFT) . ".{$ext}";
+ }
+
}
--
Gitblit v1.9.2