图片上传
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user