Upload folder using huggingface_hub
Browse files- art.py +17 -0
- communityview.py +4 -1
art.py
CHANGED
|
@@ -135,6 +135,23 @@ def font_css():
|
|
| 135 |
)
|
| 136 |
|
| 137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
def banner_image(title):
|
| 139 |
"""A generated stand-in card for a community entry with no picture: a palette-coloured
|
| 140 |
banner with the title's initial — the gallery caption carries the title itself."""
|
|
|
|
| 135 |
)
|
| 136 |
|
| 137 |
|
| 138 |
+
THUMB_SIZE = (
|
| 139 |
+
512 # px cap for gallery cards; the full art stays for the in-game backdrop
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def thumbnail(path):
|
| 144 |
+
"""A downscaled copy cached beside the original, for browsing — community pictures
|
| 145 |
+
can be huge and the gallery card doesn't need the full art."""
|
| 146 |
+
src = Path(path)
|
| 147 |
+
dest = src.with_name(f"thumb-{src.name}")
|
| 148 |
+
if not dest.exists():
|
| 149 |
+
with Image.open(src) as img:
|
| 150 |
+
img.thumbnail((THUMB_SIZE, THUMB_SIZE))
|
| 151 |
+
img.save(dest)
|
| 152 |
+
return str(dest)
|
| 153 |
+
|
| 154 |
+
|
| 155 |
def banner_image(title):
|
| 156 |
"""A generated stand-in card for a community entry with no picture: a palette-coloured
|
| 157 |
banner with the title's initial — the gallery caption carries the title itself."""
|
communityview.py
CHANGED
|
@@ -12,7 +12,10 @@ import creator
|
|
| 12 |
|
| 13 |
def gallery_items(entries):
|
| 14 |
return [
|
| 15 |
-
(
|
|
|
|
|
|
|
|
|
|
| 16 |
for e in entries
|
| 17 |
]
|
| 18 |
|
|
|
|
| 12 |
|
| 13 |
def gallery_items(entries):
|
| 14 |
return [
|
| 15 |
+
(
|
| 16 |
+
art.thumbnail(e.image) if e.image else art.banner_image(e.spec.title),
|
| 17 |
+
e.spec.title or "Untitled",
|
| 18 |
+
)
|
| 19 |
for e in entries
|
| 20 |
]
|
| 21 |
|