Fix generovani titulni fotky pro og:image

This commit is contained in:
Michal Kváček
2024-09-03 16:24:22 +02:00
parent 365a1fc1b0
commit 186dbd0720
3 changed files with 38 additions and 7 deletions
+24
View File
@@ -1,4 +1,8 @@
from PIL import Image, ImageDraw, ImageOps
from sqlalchemy import select
from database import models
from database.transaction import get_session
async def add_circular_avatar(base_image_path, avatar_image_path, output_image_path):
@@ -56,3 +60,23 @@ async def add_circular_avatar(base_image_path, avatar_image_path, output_image_p
# Save the result
base_image.save(output_image_path)
async def generate_flight_title_photo(flight_id: int, photo_id: int):
async with get_session() as db:
photo = await models.Photo.get_one(db, id=photo_id)
pilot = (await db.scalars(
select(models.User)
.select_from(models.Flight)
.join(models.Flight.created_by)
.filter(models.Flight.id == flight_id)
)).one()
photo_filename, photo_ext = photo.filename, photo.filename_extension
pilot_id, avatar_filename = pilot.id, pilot.avatar_image_filename
await add_circular_avatar(
base_image_path=f'/app/uploads/photos/{flight_id}/{photo_filename}.{photo_ext}',
avatar_image_path=f'/app/uploads/profile/{pilot_id}/{avatar_filename}',
output_image_path=f'/app/uploads/photos/{flight_id}/title_photo.jpg',
)