图片上传

This commit is contained in:
2025-06-17 15:15:08 +08:00
parent fb10df78f5
commit 2cf2c19d91
2 changed files with 2 additions and 4 deletions

View File

@@ -14,7 +14,6 @@ class ImageController extends Controller
$image = request()->file('image'); $image = request()->file('image');
$pid = request()->file('pid'); $pid = request()->file('pid');
dd($image);
return new ImageService()->processImage($image, $pid); return new ImageService()->processImage($image, $pid);
} }
} }

View File

@@ -17,9 +17,8 @@ class ImageService
*/ */
public function processImage($imageFile, $pid = 1) public function processImage($imageFile, $pid = 1)
{ {
return $imageFile;
// 1. 保存原始图片 // 1. 保存原始图片
$originalPath = $this->storeOriginalImage(file_get_contents($imageFile)); $originalPath = $this->storeOriginalImage($imageFile);
// 2. 无损压缩图片 // 2. 无损压缩图片
$compressedPath = $this->compressToWebp($originalPath); $compressedPath = $this->compressToWebp($originalPath);
@@ -48,7 +47,7 @@ class ImageService
protected function storeOriginalImage($imageFile) protected function storeOriginalImage($imageFile)
{ {
$path = 'images/original/cc_'. date('Ymdhis') . Str::random(40) . '.' . $imageFile->getClientOriginalExtension(); $path = 'images/original/cc_'. date('Ymdhis') . Str::random(40) . '.' . $imageFile->getClientOriginalExtension();
Storage::put($path, $imageFile); Storage::put($path, file_get_contents($imageFile));
return $path; return $path;
} }