更新功能:数据字典和定时任务
This commit is contained in:
@@ -5,7 +5,8 @@ namespace App\Services\System;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\Facades\Image;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Intervention\Image\Drivers\Gd\Driver;
|
||||
|
||||
class UploadService
|
||||
{
|
||||
@@ -17,6 +18,7 @@ class UploadService
|
||||
public function __construct()
|
||||
{
|
||||
$this->disk = Storage::disk('public');
|
||||
$this->imageManager = new ImageManager(new Driver());
|
||||
}
|
||||
|
||||
public function upload(UploadedFile $file, string $directory = 'uploads', array $options = []): array
|
||||
@@ -135,17 +137,14 @@ class UploadService
|
||||
$width = $options['width'] ?? null;
|
||||
$height = $options['height'] ?? null;
|
||||
|
||||
$image = Image::make($file);
|
||||
$image = $this->imageManager->read($file);
|
||||
|
||||
if ($width || $height) {
|
||||
$image->resize($width, $height, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
});
|
||||
$image->scale($width, $height);
|
||||
}
|
||||
|
||||
$image->encode(null, $quality);
|
||||
$this->disk->put($filePath, (string) $image);
|
||||
$encoded = $image->toJpeg(quality: $quality);
|
||||
$this->disk->put($filePath, (string) $encoded);
|
||||
}
|
||||
|
||||
public function getFileUrl(string $path): string
|
||||
|
||||
Reference in New Issue
Block a user