Pridani editace fotek
This commit is contained in:
@@ -19,23 +19,23 @@ async def add_terrain_elevation_to_flight(flight_id: int, gpx_filename: str):
|
||||
async with get_session() as db:
|
||||
await models.Flight.update(
|
||||
db, {"gpx_track_filename": output_name, "has_terrain_elevation": True},
|
||||
id=flight_id)
|
||||
|
||||
id=flight_id
|
||||
)
|
||||
except ClientResponseError as e:
|
||||
print(e)
|
||||
|
||||
|
||||
async def add_terrain_elevation_to_photo(photo):
|
||||
async with get_session() as db:
|
||||
try:
|
||||
elevation = await elevation_api.get_elevation_for_points([
|
||||
{"lat": photo.gps_latitude, "lng": photo.gps_longitude}
|
||||
])
|
||||
if not elevation:
|
||||
print("Cannot get elevation")
|
||||
return
|
||||
try:
|
||||
elevation = await elevation_api.get_elevation_for_points([
|
||||
{"lat": photo.gps_latitude, "lng": photo.gps_longitude}
|
||||
])
|
||||
if not elevation:
|
||||
print("Cannot get elevation")
|
||||
return
|
||||
|
||||
terrain_elevation = elevation[0]['elevation']
|
||||
terrain_elevation = elevation[0]['elevation']
|
||||
async with get_session() as db:
|
||||
await models.Photo.update(db_session=db, obj=photo, data={"terrain_elevation": terrain_elevation})
|
||||
except Exception as e:
|
||||
print(f"Cannot get elevation: {e}")
|
||||
except Exception as e:
|
||||
print(f"Cannot get elevation: {e}")
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
from utils.image import resize_image
|
||||
from database import models
|
||||
from database.transaction import get_session
|
||||
from utils.image import PhotoEditor
|
||||
|
||||
|
||||
async def resize_photo(path: str, filename: str):
|
||||
return await resize_image(path, filename, new_width=2500, quality=85)
|
||||
async def resize_photo(path: str, filename: str, photo_id: int):
|
||||
editor = PhotoEditor(path, filename)
|
||||
editor.resize(new_width=2500)
|
||||
editor.write_to_file(quality=85)
|
||||
width, height = editor.img_size
|
||||
|
||||
async with get_session() as db:
|
||||
await models.Photo.update(db, {"width": width, "height": height}, id=photo_id)
|
||||
|
||||
|
||||
async def generate_thumbnail(path: str, filename: str, quality: int = 90):
|
||||
return await resize_image(
|
||||
path, filename,
|
||||
new_width=300,
|
||||
dest_path=f"{path}/thumbs/",
|
||||
dest_filename=filename,
|
||||
quality=quality
|
||||
)
|
||||
async def generate_thumbnail(path: str, filename: str):
|
||||
editor = PhotoEditor(path, filename)
|
||||
editor.resize(new_width=300)
|
||||
editor.write_to_file(quality=85, dest_path=f"{path}/thumbs/")
|
||||
Reference in New Issue
Block a user