mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Allow upload of SVG images
This commit is contained in:
parent
da7e68ea08
commit
d519ad9b66
@ -9,7 +9,13 @@ from django.forms.fields import FileField, ImageField
|
|||||||
from django.template.defaultfilters import filesizeformat
|
from django.template.defaultfilters import filesizeformat
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
ALLOWED_EXTENSIONS = ["gif", "jpg", "jpeg", "png", "webp"]
|
ALLOW_SVG = getattr(settings, "WAGTAILIMAGES_ALLOW_SVG", False)
|
||||||
|
if ALLOW_SVG:
|
||||||
|
ALLOWED_EXTENSIONS = ["gif", "jpg", "jpeg", "png", "webp", "svg"]
|
||||||
|
SUPPORTED_FORMATS_TEXT = _("GIF, JPEG, PNG, WEBP, SVG")
|
||||||
|
else:
|
||||||
|
ALLOWED_EXTENSIONS = ["gif", "jpg", "jpeg", "png", "webp"]
|
||||||
|
SUPPORTED_FORMATS_TEXT = _("GIF, JPEG, PNG, WEBP")
|
||||||
|
|
||||||
|
|
||||||
class WagtailImageField(ImageField):
|
class WagtailImageField(ImageField):
|
||||||
|
@ -47,6 +47,7 @@ IMAGE_FORMAT_EXTENSIONS = {
|
|||||||
"png": ".png",
|
"png": ".png",
|
||||||
"gif": ".gif",
|
"gif": ".gif",
|
||||||
"webp": ".webp",
|
"webp": ".webp",
|
||||||
|
"svg": ".svg",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -579,6 +580,9 @@ class AbstractImage(ImageFileMixin, CollectionMember, index.Indexed, models.Mode
|
|||||||
def is_landscape(self):
|
def is_landscape(self):
|
||||||
return self.height < self.width
|
return self.height < self.width
|
||||||
|
|
||||||
|
def is_svg(self):
|
||||||
|
return self.file.name.endswith(".svg")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def filename(self):
|
def filename(self):
|
||||||
return os.path.basename(self.file.name)
|
return os.path.basename(self.file.name)
|
||||||
@ -761,6 +765,8 @@ class Filter:
|
|||||||
quality = getattr(settings, "WAGTAILIMAGES_WEBP_QUALITY", 85)
|
quality = getattr(settings, "WAGTAILIMAGES_WEBP_QUALITY", 85)
|
||||||
|
|
||||||
return willow.save_as_webp(output, quality=quality)
|
return willow.save_as_webp(output, quality=quality)
|
||||||
|
elif output_format == "svg":
|
||||||
|
return willow.save_as_svg(output)
|
||||||
raise UnknownOutputImageFormatError(
|
raise UnknownOutputImageFormatError(
|
||||||
f"Unknown output image format '{output_format}'"
|
f"Unknown output image format '{output_format}'"
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user