diff --git a/app/Exports/ZipExports/Models/ZipExportImage.php b/app/Exports/ZipExports/Models/ZipExportImage.php index e0e7d11986d..4c70f15317a 100644 --- a/app/Exports/ZipExports/Models/ZipExportImage.php +++ b/app/Exports/ZipExports/Models/ZipExportImage.php @@ -32,7 +32,7 @@ public function metadataOnly(): void public static function validate(ZipValidationHelper $context, array $data): array { - $acceptedImageTypes = ['image/png', 'image/jpeg', 'image/gif', 'image/webp']; + $acceptedImageTypes = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/svg+xml']; $rules = [ 'id' => ['nullable', 'int', $context->uniqueIdRule('image')], 'name' => ['required', 'string', 'min:1'], diff --git a/app/Http/Controller.php b/app/Http/Controller.php index 090cf523ad2..3be0020605f 100644 --- a/app/Http/Controller.php +++ b/app/Http/Controller.php @@ -163,7 +163,7 @@ protected function logActivity(string $type, string|Loggable $detail = ''): void */ protected function getImageValidationRules(): array { - return ['image_extension', 'mimes:jpeg,png,gif,webp', 'max:' . (config('app.upload_limit') * 1000)]; + return ['image_extension', 'mimes:jpeg,png,gif,webp,svg', 'max:' . (config('app.upload_limit') * 1000)]; } /** diff --git a/app/Uploads/ImageResizer.php b/app/Uploads/ImageResizer.php index fa6b1cac2d4..883122e177f 100644 --- a/app/Uploads/ImageResizer.php +++ b/app/Uploads/ImageResizer.php @@ -66,6 +66,11 @@ public function resizeToThumbnailUrl( bool $keepRatio = false, bool $shouldCreate = false ): ?string { + // Do not attempt to resize SVGs, return the raw value always. + if ($this->isSvg($image)) { + return $this->storage->getPublicUrl($image->path); + } + // Do not resize GIF images where we're not cropping if ($keepRatio && $this->isGif($image)) { return $this->storage->getPublicUrl($image->path); @@ -226,6 +231,14 @@ protected function isGif(Image $image): bool return $this->getExtension($image) === 'gif'; } + /** + * Checks if the image is a svg. Returns true if it is, else false. + */ + protected function isSvg(Image $image): bool + { + return $this->getExtension($image) === 'svg'; + } + /** * Get the extension for the given image, normalised to lower-case. */ diff --git a/app/Uploads/ImageService.php b/app/Uploads/ImageService.php index 038e6aa417c..45c2d812116 100644 --- a/app/Uploads/ImageService.php +++ b/app/Uploads/ImageService.php @@ -13,7 +13,7 @@ class ImageService { - protected static array $supportedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp']; + protected static array $supportedExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg']; public function __construct( protected ImageStorage $storage, diff --git a/app/Util/WebSafeMimeSniffer.php b/app/Util/WebSafeMimeSniffer.php index 4a82de85d25..35c85125042 100644 --- a/app/Util/WebSafeMimeSniffer.php +++ b/app/Util/WebSafeMimeSniffer.php @@ -33,6 +33,7 @@ class WebSafeMimeSniffer 'image/webp', 'image/avif', 'image/heic', + 'image/svg+xml', 'text/css', 'text/csv', 'text/javascript',