diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index be9d95fe..55759cc6 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -165,7 +165,7 @@ class Controller extends BaseController if ( $image->group?->configs->get(GroupConfigKey::IsEnableWatermark) && $configs->get('mode', Mode::Overlay) == Mode::Dynamic && - ! in_array($image->extension, ['ico', 'gif']) + ! in_array($image->extension, ['ico', 'gif', 'svg']) ) { $contents = $service->stickWatermark($contents, $configs)->encode()->getEncoded(); } @@ -184,8 +184,8 @@ class Controller extends BaseController $mimetype = $image->mimetype; - // ico 图片直接输出,不经过 InterventionImage 处理 - if ($image->extension === 'ico') { + // ico svg 图片直接输出,不经过 InterventionImage 处理 + if (in_array($image->extension, ['ico', 'svg'])) { goto out; } diff --git a/app/Http/Requests/Admin/GroupRequest.php b/app/Http/Requests/Admin/GroupRequest.php index d2ef4d20..0f1e9b33 100644 --- a/app/Http/Requests/Admin/GroupRequest.php +++ b/app/Http/Requests/Admin/GroupRequest.php @@ -38,7 +38,7 @@ class GroupRequest extends FormRequest 'configs.image_save_format' => '', 'configs.path_naming_rule' => 'max:400', 'configs.file_naming_rule' => 'max:400', - 'configs.accepted_file_suffixes' => 'required|array|in:jpeg,jpg,png,gif,tif,bmp,ico,psd,webp', + 'configs.accepted_file_suffixes' => 'required|array|in:jpeg,jpg,png,gif,tif,bmp,ico,psd,webp,svg', 'configs.is_enable_scan' => 'boolean', 'configs.scanned_action' => [ diff --git a/app/Services/ImageService.php b/app/Services/ImageService.php index ec90e423..7f307e6d 100644 --- a/app/Services/ImageService.php +++ b/app/Services/ImageService.php @@ -151,8 +151,8 @@ class ImageService // 上传频率限制 $this->rateLimiter($configs, $request); - // 图片处理,跳过 ico 于 gif - if (! in_array($extension, ['ico', 'gif'])) { + // 图片处理,跳过 ico gif svg + if (! in_array($extension, ['ico', 'gif', 'svg'])) { // 图片保存质量与格式 $quality = $configs->get(GroupConfigKey::ImageSaveQuality, 75); $format = $configs->get(GroupConfigKey::ImageSaveFormat); @@ -245,8 +245,8 @@ class ImageService throw new UploadException('图片记录保存失败'); } - // 图片检测,跳过 tif、ico 以及 psd 格式 - if ($configs->get(GroupConfigKey::IsEnableScan) && ! in_array($extension, ['psd', 'ico', 'tif'])) { + // 图片检测,跳过 tif、ico、psd、svg 格式 + if ($configs->get(GroupConfigKey::IsEnableScan) && ! in_array($extension, ['psd', 'ico', 'tif', 'svg'])) { $scanConfigs = $configs->get(GroupConfigKey::ScanConfigs); if ($this->scan( driver: $scanConfigs['driver'], @@ -266,8 +266,10 @@ class ImageService } } - // 生成缩略图 - $this->makeThumbnail($image, $file); + // 生成缩略图,svg等格式本身体积足够小且网页原生支持(比生成的png缩略图还小),不用生成缩略图 + if(!in_array($extension, ['svg'])) { + $this->makeThumbnail($image, $file); + } return $image; } diff --git a/config/convention.php b/config/convention.php index e53e2810..513ddd2c 100644 --- a/config/convention.php +++ b/config/convention.php @@ -106,7 +106,7 @@ return [ GroupConfigKey::LimitPerDay => 300, GroupConfigKey::LimitPerWeek => 600, GroupConfigKey::LimitPerMonth => 999, - GroupConfigKey::AcceptedFileSuffixes => ['jpeg', 'jpg', 'png', 'gif', 'tif', 'bmp', 'ico', 'psd', 'webp'], + GroupConfigKey::AcceptedFileSuffixes => ['jpeg', 'jpg', 'png', 'gif', 'tif', 'bmp', 'ico', 'psd', 'webp', 'svg'], GroupConfigKey::ImageSaveFormat => '', GroupConfigKey::ImageSaveQuality => 75, GroupConfigKey::PathNamingRule => '{Y}/{m}/{d}',