Fix generovani titulni fotky pro og:image
This commit is contained in:
@@ -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',
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user