Re-added webp fallback
This commit is contained in:
parent
1bed47fbf5
commit
53811ca9b2
@ -181,12 +181,12 @@ def enrich_image_rendering(text):
|
|||||||
soup = BeautifulSoup(text, "html.parser")
|
soup = BeautifulSoup(text, "html.parser")
|
||||||
for element in soup.find_all("img"):
|
for element in soup.find_all("img"):
|
||||||
if element.attrs["src"].startswith("/"):
|
if element.attrs["src"].startswith("/"):
|
||||||
element.attrs["src"] += "?width=240&height=240&format=webp"
|
element.attrs["src"] += "?width=240&height=240"
|
||||||
picture_template = f'''
|
picture_template = f'''
|
||||||
<picture>
|
<picture>
|
||||||
<source srcset="{element.attrs["src"]}" type="{mimetypes.guess_type(element.attrs["src"])[0]}" />
|
<source srcset="{element.attrs["src"]}" type="{mimetypes.guess_type(element.attrs["src"])[0]}" />
|
||||||
<source srcset="{element.attrs["src"]}" type="image/webp" />
|
<source srcset="{element.attrs["src"]}&format=webp" type="image/webp" />
|
||||||
<img src="{element.attrs["src"]}" title="{element.attrs["src"]}" alt="{element.attrs["src"]}" />
|
<img src="{element.attrs["src"]}&format=png" title="{element.attrs["src"]}" alt="{element.attrs["src"]}" />
|
||||||
</picture>'''
|
</picture>'''
|
||||||
element.replace_with(BeautifulSoup(picture_template, "html.parser"))
|
element.replace_with(BeautifulSoup(picture_template, "html.parser"))
|
||||||
return str(soup)
|
return str(soup)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
from os.path import isfile
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import pillow_heif.HeifImagePlugin
|
import pillow_heif.HeifImagePlugin
|
||||||
@ -17,7 +18,7 @@ class ChannelAttachmentView(BaseView):
|
|||||||
relative_url=relative_path
|
relative_url=relative_path
|
||||||
)
|
)
|
||||||
|
|
||||||
if not channel_attachment:
|
if not channel_attachment or not isfile(channel_attachment["path"]):
|
||||||
return web.HTTPNotFound()
|
return web.HTTPNotFound()
|
||||||
|
|
||||||
original_format = mimetypes.guess_type(channel_attachment["path"])[0]
|
original_format = mimetypes.guess_type(channel_attachment["path"])[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user