Skip to content

Add .svg extension to supported image file extensions #5418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Exports/ZipExports/Models/ZipExportImage.php
Original file line number Diff line number Diff line change
@@ -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'],
2 changes: 1 addition & 1 deletion app/Http/Controller.php
Original file line number Diff line number Diff line change
@@ -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)];
}

/**
13 changes: 13 additions & 0 deletions app/Uploads/ImageResizer.php
Original file line number Diff line number Diff line change
@@ -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.
*/
2 changes: 1 addition & 1 deletion app/Uploads/ImageService.php
Original file line number Diff line number Diff line change
@@ -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,
1 change: 1 addition & 0 deletions app/Util/WebSafeMimeSniffer.php
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ class WebSafeMimeSniffer
'image/webp',
'image/avif',
'image/heic',
'image/svg+xml',
'text/css',
'text/csv',
'text/javascript',