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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user