diff --git a/app/Http/Controllers/ChatController.php b/app/Http/Controllers/ChatController.php index 7ecbbb7..c3b22c8 100644 --- a/app/Http/Controllers/ChatController.php +++ b/app/Http/Controllers/ChatController.php @@ -714,7 +714,7 @@ class ChatController extends Controller public function uploadAvatar(Request $request): JsonResponse { $request->validate([ - 'file' => 'required|image|mimes:jpeg,png,jpg,gif,webp|max:2048', + 'file' => 'required|image|mimes:jpeg,png,jpg,gif,webp|max:6144', ]); $user = Auth::user(); @@ -726,17 +726,22 @@ class ChatController extends Controller try { $manager = new ImageManager(new Driver); - $image = $manager->read($file); - - // 裁剪正方形并压缩为 112x112 - $image->cover(112, 112); // 生成相对路径 $filename = 'custom_'.$user->id.'_'.time().'.'.$file->extension(); + $originalFilename = 'custom_'.$user->id.'_'.time().'_original.'.$file->extension(); $path = 'avatars/'.$filename; + $originalPath = 'avatars/'.$originalFilename; - // 保存以高质量 JPG 或原格式 - Storage::disk('public')->put($path, (string) $image->encode()); + // 1. 处理原图:限制最大宽度为 1280 以免过大,保存原比例高清大图 + $originalImage = $manager->read($file); + $originalImage->scaleDown(width: 1280); + Storage::disk('public')->put($originalPath, (string) $originalImage->encode()); + + // 2. 处理缩略图:裁剪正方形并压缩为 112x112 + $thumbImage = $manager->read($file); + $thumbImage->cover(112, 112); + Storage::disk('public')->put($path, (string) $thumbImage->encode()); $dbValue = 'storage/'.$path; diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 5529256..81716f0 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -40,6 +40,16 @@ class UserController extends Controller $targetUser = User::where('username', $username)->firstOrFail(); $operator = Auth::user(); + // 探测原图 + $headfaceOriginal = $targetUser->headfaceUrl; + if (str_starts_with((string) $targetUser->headface, 'storage/')) { + $info = pathinfo($targetUser->headface); + $origPath = $info['dirname'].'/'.$info['filename'].'_original.'.($info['extension'] ?? 'jpg'); + if (\Illuminate\Support\Facades\Storage::disk('public')->exists(substr($origPath, 8))) { + $headfaceOriginal = '/'.$origPath; + } + } + // 基础公开信息 $activePosition = $targetUser->activePosition?->load('position.department')->position; $data = [ @@ -48,6 +58,7 @@ class UserController extends Controller 1 => '男', 2 => '女', default => '' }, 'headface' => $targetUser->headface, + 'headface_original' => $headfaceOriginal, 'usersf' => $targetUser->usersf, 'user_level' => $targetUser->user_level, 'qianming' => $targetUser->qianming, diff --git a/app/Models/User.php b/app/Models/User.php index 093bc80..662e719 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -141,7 +141,10 @@ class User extends Authenticatable $hf = (string) $this->usersf; if (str_starts_with($hf, 'storage/')) { $path = substr($hf, 8); // 去除 'storage/' 前缀 - \Illuminate\Support\Facades\Storage::disk('public')->delete($path); + $info = pathinfo($path); + $origPath = $info['dirname'].'/'.$info['filename'].'_original.'.($info['extension'] ?? 'jpg'); + + \Illuminate\Support\Facades\Storage::disk('public')->delete([$path, $origPath]); } } diff --git a/resources/views/chat/frame.blade.php b/resources/views/chat/frame.blade.php index aa6fd57..7bf6409 100644 --- a/resources/views/chat/frame.blade.php +++ b/resources/views/chat/frame.blade.php @@ -56,6 +56,7 @@ 'username' => $botUser->username, 'level' => $botUser->user_level, 'sex' => $botUser->sex, + 'headface' => $botUser->headface, 'headfaceUrl' => $botUser->headfaceUrl, 'vip_icon' => $botUser->vipIcon(), 'vip_name' => $botUser->vipName(), diff --git a/resources/views/chat/partials/user-actions.blade.php b/resources/views/chat/partials/user-actions.blade.php index b11b370..b3d1337 100644 --- a/resources/views/chat/partials/user-actions.blade.php +++ b/resources/views/chat/partials/user-actions.blade.php @@ -87,6 +87,7 @@ function userCardComponent() { return { showUserModal: false, + showOriginalLightbox: false, userInfo: { position_history: [] }, @@ -605,7 +606,12 @@