generated from hjess/PythonTemplateProject
[main] Imagesizes in slider
All checks were successful
Build, Push, and Deploy to Nomad / docker-nomad (push) Successful in 53s
All checks were successful
Build, Push, and Deploy to Nomad / docker-nomad (push) Successful in 53s
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -7,9 +7,10 @@ from PIL import Image
|
||||
|
||||
class FileHandler:
|
||||
|
||||
def __init__(self, category, image_type, filename):
|
||||
def __init__(self, category=None, image_type=None, filename=None):
|
||||
self.filename = filename
|
||||
self.category = category
|
||||
|
||||
self.image_type = image_type
|
||||
|
||||
@property
|
||||
@@ -44,6 +45,20 @@ class FileHandler:
|
||||
f")"
|
||||
)
|
||||
|
||||
def get_category(self, file_path):
|
||||
# List all categories in the data directory
|
||||
categories = [
|
||||
name for name in os.listdir( "data/" )
|
||||
if os.path.isdir( os.path.join( "data/", name ) )
|
||||
]
|
||||
|
||||
# Search for the category in the file path
|
||||
for category in categories:
|
||||
if f"/{category}/" in file_path or f"\\{category}\\" in file_path:
|
||||
return category
|
||||
|
||||
# Return None if no category matches
|
||||
return None
|
||||
|
||||
|
||||
class ImageService:
|
||||
@@ -139,14 +154,10 @@ class ImageService:
|
||||
default_size = self.get_image_size( image_type)
|
||||
width = width or default_size.get( "width" )
|
||||
height = height or default_size.get( "height" )
|
||||
|
||||
|
||||
|
||||
#file_path = self._resolve_path( category, image_type, filename )
|
||||
file_path = FileHandler(category = category,image_type = image_type,filename = filename)
|
||||
self.validate_image( file_path, width = width,height=height, overwrite = True )
|
||||
|
||||
tag = f'<img src="{file_path.dest_filename}" alt="{alt}"'
|
||||
tag = f'<img src="/{file_path.dest_filename}" alt="{alt}"'
|
||||
if width:
|
||||
tag += f' width="{width}"'
|
||||
if height:
|
||||
|
||||
@@ -4,7 +4,8 @@ import markdown
|
||||
from fastapi import FastAPI
|
||||
from jinja2 import Environment, DictLoader
|
||||
from markupsafe import Markup
|
||||
from .image_service import ImageService
|
||||
from .image_service import ImageService, FileHandler
|
||||
|
||||
|
||||
class MarkdownRenderer:
|
||||
def __init__(self, file_path: str = None, app: FastAPI=None):
|
||||
@@ -88,18 +89,21 @@ class MarkdownRenderer:
|
||||
html_content.append('<div class="button-stack">')
|
||||
for i, val in enumerate(images):
|
||||
self.image_service = ImageService( self.app )
|
||||
print(val)
|
||||
modal_id_current = f"{modal_id}_{i}"
|
||||
modal_id_next = f"{modal_id}_{i + 1}" if i + 1 < len(images) else f"{modal_id}_0"
|
||||
|
||||
category = FileHandler().get_category(self.file_path)
|
||||
|
||||
thumbnal_img = self.image_service.image_tag(category = category, image_type = "thumbnails",filename = val,alt="A better description later on")
|
||||
modal_img = self.image_service.image_tag(category = category, image_type = "large",filename = val,alt="A better description later on")
|
||||
html_content.append(f"""
|
||||
<button onclick="openModal('modal{modal_id_current}')" class="stacked-button">
|
||||
<img src="{val}" alt="Image {i}" class="thumbnail" loading="lazy">
|
||||
{thumbnal_img}
|
||||
</button>
|
||||
<div class="modal" id="modal{modal_id_current}">
|
||||
<div class="modal-content">
|
||||
<h2>Modal {i}</h2>
|
||||
<img src="{val}" alt="Image {i}" loading="lazy">
|
||||
{modal_img}
|
||||
|
||||
<div class="modal-buttons">
|
||||
<button onclick="closeModal('modal{modal_id_current}')">Close</button>
|
||||
@@ -136,9 +140,8 @@ class MarkdownRenderer:
|
||||
width=width,
|
||||
height=height
|
||||
)
|
||||
my_tag = Markup(tag)
|
||||
print(my_tag)
|
||||
return my_tag
|
||||
return Markup(tag)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ Ligesom i København, hvor du finder både små biografer som Grand Teatret og s
|
||||
|
||||
|
||||
|
||||
{{ slider(options={"width": 500, "height": 500}, images=["158177.jpg", "158170.jpg", "Fachada_SaoJorge.jpg"]) }}
|
||||
{{ slider(options={"width": 500, "height": 500}, images=["158170.jpg", "Fachada_SaoJorge.jpg"]) }}
|
||||
|
||||
Biografbesøg i Lissabon er en afslappet måde at tilbringe tid med familien. Jeg nyder selv at tage afsted med Erika for at dele både film og hygge.
|
||||
|
||||
@@ -73,4 +73,4 @@ Samtidig er mange oplevelser billigere end i København, og her er en atmosfære
|
||||
### Lidt billeder
|
||||
|
||||
|
||||
{{ slider(options={"width": 500, "height": 500}, images=["158170.jpg", "Fachada_SaoJorge.jpg", "pic34.jpg", "pic42.jpg", "pic72.jpg", "pic94.jpg"]) }}
|
||||
{{ slider(options={"width": 500, "height": 500}, images=["158170.jpg", "Fachada_SaoJorge.jpg"]) }}
|
||||
BIN
static/images/Kultur/large/158170.jpg
Normal file
BIN
static/images/Kultur/large/158170.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 60 KiB |
BIN
static/images/Kultur/large/Fachada_SaoJorge.jpg
Normal file
BIN
static/images/Kultur/large/Fachada_SaoJorge.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 109 KiB |
BIN
static/images/Kultur/thumbnails/158170.jpg
Normal file
BIN
static/images/Kultur/thumbnails/158170.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
BIN
static/images/Kultur/thumbnails/Fachada_SaoJorge.jpg
Normal file
BIN
static/images/Kultur/thumbnails/Fachada_SaoJorge.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Reference in New Issue
Block a user