diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 049ddb1..f839a32 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -9,9 +9,11 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Storage; use Illuminate\View\View; +use App\Traits\ImageHandler; class ProfileController extends Controller { + use ImageHandler; /** * Display the user's profile form. */ @@ -48,7 +50,7 @@ class ProfileController extends Controller public function updateAvatar(Request $request): \Illuminate\Http\JsonResponse { $request->validate([ - 'avatar' => ['required', 'image', 'mimes:jpeg,png,jpg,gif,webp', 'max:1024'], + 'avatar' => ['required', 'image', 'mimes:jpeg,png,jpg,gif,webp', 'max:5120'], ]); $user = $request->user(); @@ -59,7 +61,8 @@ class ProfileController extends Controller Storage::disk('public')->delete($user->avatar); } - $path = $request->file('avatar')->store('avatars', 'public'); + // 將上傳的大頭貼轉換為高壓縮率且清晰的 WebP 格式 (300x300 居中裁切) + $path = $this->storeAsWebp($request->file('avatar'), 'avatars', 85, 300, 300); $user->avatar = $path; $user->save(); diff --git a/app/Http/Requests/ProfileUpdateRequest.php b/app/Http/Requests/ProfileUpdateRequest.php index f4a10f8..9e5ded7 100644 --- a/app/Http/Requests/ProfileUpdateRequest.php +++ b/app/Http/Requests/ProfileUpdateRequest.php @@ -19,7 +19,7 @@ class ProfileUpdateRequest extends FormRequest 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)], 'phone' => ['nullable', 'string', 'max:20'], - 'avatar' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif', 'max:2048'], + 'avatar' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,webp', 'max:5120'], ]; } } diff --git a/lang/en.json b/lang/en.json index 447b741..0b6003e 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1616,6 +1616,7 @@ "The Super Admin role is immutable.": "The Super Admin role is immutable.", "The Super Admin role name cannot be modified.": "The Super Admin role name cannot be modified.", "The image is too large. Please upload an image smaller than 1MB.": "The image is too large. Please upload an image smaller than 1MB.", + "The image is too large. Please upload an image smaller than 5MB.": "The image is too large. Please upload an image smaller than 5MB.", "This is a system administrator role. Its name is locked to ensure system stability.": "This is a system administrator role. Its name is locked to ensure system stability.", "This machine has a pending command. Please wait.": "This machine has a pending command. Please wait.", "This role belongs to another company and cannot be assigned.": "This role belongs to another company and cannot be assigned.", diff --git a/lang/ja.json b/lang/ja.json index 2c012c2..af811ed 100644 --- a/lang/ja.json +++ b/lang/ja.json @@ -1616,6 +1616,7 @@ "The Super Admin role is immutable.": "特権管理者ロールは変更できません。", "The Super Admin role name cannot be modified.": "特権管理者ロールの名前は変更できません。", "The image is too large. Please upload an image smaller than 1MB.": "画像サイズが大きすぎます。1MB未満の画像をアップロードしてください。", + "The image is too large. Please upload an image smaller than 5MB.": "画像サイズが大きすぎます。5MB未満の画像をアップロードしてください。", "This is a system administrator role. Its name is locked to ensure system stability.": "これはシステム管理者ロールです。システムの安定性を確保するため、名前はロックされています。", "This machine has a pending command. Please wait.": "この機器には実行中のコマンドがあります。しばらくお待ちください。", "This role belongs to another company and cannot be assigned.": "このロールは別の会社に属しているため、割り当てることができません。", diff --git a/lang/zh_TW.json b/lang/zh_TW.json index e55b14a..370fcc9 100644 --- a/lang/zh_TW.json +++ b/lang/zh_TW.json @@ -1638,6 +1638,7 @@ "The Super Admin role is immutable.": "超級管理員角色不可修改。", "The Super Admin role name cannot be modified.": "超級管理員角色的名稱無法修改。", "The image is too large. Please upload an image smaller than 1MB.": "圖片檔案太大,請上傳小於 1MB 的圖片。", + "The image is too large. Please upload an image smaller than 5MB.": "圖片檔案太大,請上傳小於 5MB 的圖片。", "This is a system administrator role. Its name is locked to ensure system stability.": "這是系統管理員角色,名稱已鎖定以確保系統穩定性。", "This machine has a pending command. Please wait.": "此機台已有指令正在執行,請稍後。", "This role belongs to another company and cannot be assigned.": "此角色屬於其他公司,無法指派。", diff --git a/resources/views/profile/edit.blade.php b/resources/views/profile/edit.blade.php index 1dbb847..1ee3d4e 100644 --- a/resources/views/profile/edit.blade.php +++ b/resources/views/profile/edit.blade.php @@ -8,9 +8,9 @@ const file = event.target.files[0]; if (!file) return; - // Size Check (1MB = 1024 * 1024 bytes) - if (file.size > 1024 * 1024) { - alert('{{ __('The image is too large. Please upload an image smaller than 1MB.') }}'); + // Size Check (5MB = 5 * 1024 * 1024 bytes) + if (file.size > 5 * 1024 * 1024) { + alert('{{ __('The image is too large. Please upload an image smaller than 5MB.') }}'); return; }