First Commit

This commit is contained in:
2023-09-10 23:50:05 +04:00
commit 6d45d1c604
61 changed files with 19953 additions and 0 deletions

View File

View File

View File

@@ -0,0 +1,12 @@
from pathlib import Path
from os import remove
async def mkdir_if_not_exists(path: Path) -> None:
if not path.exists():
path.mkdir(parents=True)
def remove_file(file_path: str) -> None:
try: remove(file_path)
except FileNotFoundError: ...

View File

@@ -0,0 +1,25 @@
from pathlib import Path
from PIL import Image
from app.utils.file_operations import mkdir_if_not_exists
async def generate_unique_image_name(
path: Path,
image_name: Path | str,
image_format: str
) -> Path | str:
number = 1
temp_image_name = image_name
while (path / temp_image_name).exists():
temp_image_name = f'{image_name}-{number}.{image_format}'
number += 1
return temp_image_name
async def save_image(image: Image, image_path: Path) -> None:
await mkdir_if_not_exists(image_path.parent)
image.save(image_path)