[FEAT] 實作維修管理模組與 RBAC 權限整合、多語系支援及 UI 優化
All checks were successful
star-cloud-deploy-demo / deploy-demo (push) Successful in 1m3s
All checks were successful
star-cloud-deploy-demo / deploy-demo (push) Successful in 1m3s
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin\BasicSettings;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Machine\Machine;
|
||||
use App\Traits\ImageHandler;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -11,6 +12,8 @@ use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class MachinePhotoController extends Controller
|
||||
{
|
||||
use ImageHandler;
|
||||
|
||||
/**
|
||||
* 更新機台照片
|
||||
*/
|
||||
@@ -64,50 +67,4 @@ class MachinePhotoController extends Controller
|
||||
return back()->with('error', __('Failed to update machine images: ') . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 將圖片轉換為 WebP 並儲存
|
||||
*/
|
||||
protected function storeAsWebp($file, $directory): string
|
||||
{
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
$filename = uniqid() . '.webp';
|
||||
$path = "{$directory}/{$filename}";
|
||||
|
||||
// 讀取原始圖片
|
||||
$imageType = exif_imagetype($file->getRealPath());
|
||||
switch ($imageType) {
|
||||
case IMAGETYPE_JPEG:
|
||||
$source = imagecreatefromjpeg($file->getRealPath());
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$source = imagecreatefrompng($file->getRealPath());
|
||||
break;
|
||||
case IMAGETYPE_WEBP:
|
||||
$source = imagecreatefromwebp($file->getRealPath());
|
||||
break;
|
||||
default:
|
||||
// 如果格式不支援,直接存
|
||||
return $file->storeAs($directory, $file->hashName(), 'public');
|
||||
}
|
||||
|
||||
if (!$source) {
|
||||
return $file->storeAs($directory, $file->hashName(), 'public');
|
||||
}
|
||||
|
||||
// 確保支援真彩色(解決 palette image 問題)
|
||||
if (!imageistruecolor($source)) {
|
||||
imagepalettetotruecolor($source);
|
||||
}
|
||||
|
||||
// 捕捉輸出
|
||||
ob_start();
|
||||
imagewebp($source, null, 80);
|
||||
$content = ob_get_clean();
|
||||
imagedestroy($source);
|
||||
|
||||
Storage::disk('public')->put($path, $content);
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user