Merge 4dbfefddd84e6adfe84e29bf6f276e0ab648c8cf into 802f69cf35abba8ff75b0ef7bbed09bbcda62816

This commit is contained in:
Thomas Jones 2025-03-31 11:16:12 -04:00 committed by GitHub
commit 0f69c18709
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 3 deletions

View File

@ -32,7 +32,7 @@ class ZipExportImage extends ZipExportModel
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'],

View File

@ -163,7 +163,7 @@ abstract class Controller extends BaseController
*/
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)];
}
/**

View File

@ -66,6 +66,11 @@ class ImageResizer
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);
@ -229,6 +234,14 @@ class ImageResizer
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.
*/

View File

@ -13,7 +13,7 @@ use Symfony\Component\HttpFoundation\StreamedResponse;
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,

View File

@ -33,6 +33,7 @@ class WebSafeMimeSniffer
'image/webp',
'image/avif',
'image/heic',
'image/svg+xml',
'text/css',
'text/csv',
'text/javascript',