Skip to content

Commit

Permalink
render images in preview
Browse files Browse the repository at this point in the history
  • Loading branch information
glwntd committed Dec 17, 2024
1 parent 5a35d87 commit bf21311
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pyglossary/ui/ui_web/server_ws_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
- Website: https://legbehindneck.com
"""
import base64

import errno
import json
import logging
Expand Down Expand Up @@ -480,10 +479,16 @@ def browse_glossary(self, path):
num_results += 1
else:
response.append(f"&#128206;<pre>{entry.s_word}</pre>")
if entry.isData() and entry.size() < MAX_IMAGE_SIZE and entry.s_word.lower().endswith(('.jpg', 'jpeg','.png')):
if (
entry.isData()
and entry.size() < MAX_IMAGE_SIZE
and entry.s_word.lower().endswith((".jpg", "jpeg", ".png"))
):
extension = Path(entry.s_word).suffix[1:]
response.append(f"""
<img class="data" src="data:image/{extension};base64,{base64.b64encode(entry.data).decode('utf-8')}" alt="{entry.s_word}"/>
<img class="data"
src="data:image/{extension};base64,{base64.b64encode(entry.data).decode('utf-8')}"
alt="{entry.s_word}"/>
""")
if num_results >= max_results:
break
Expand Down

0 comments on commit bf21311

Please sign in to comment.