upload z zjec z galerii + prettycode
This commit is contained in:
18
app.py
18
app.py
@@ -6,6 +6,7 @@ import mimetypes
|
||||
import sys
|
||||
import platform
|
||||
import psutil
|
||||
import pyheif # zdjecia heic
|
||||
|
||||
from datetime import datetime, timedelta, UTC, timezone
|
||||
|
||||
@@ -48,7 +49,7 @@ from functools import wraps
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
|
||||
ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "gif", "webp"}
|
||||
ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "gif", "webp", "heic"}
|
||||
SQLALCHEMY_ECHO = True
|
||||
|
||||
SYSTEM_PASSWORD = app.config.get("SYSTEM_PASSWORD", "changeme")
|
||||
@@ -242,10 +243,17 @@ def enrich_list_data(l):
|
||||
return l
|
||||
|
||||
|
||||
def save_resized_image(file, path: str, max_size=(2000, 2000)):
|
||||
img = Image.open(file)
|
||||
img.thumbnail(max_size)
|
||||
img.save(path)
|
||||
def save_resized_image(file, path):
|
||||
if file.filename.lower().endswith(".heic"):
|
||||
heif_file = pyheif.read_heif(file.read())
|
||||
image = Image.frombytes(
|
||||
heif_file.mode, heif_file.size, heif_file.data, "raw"
|
||||
)
|
||||
image.save(path.replace(".heic", ".jpg"), format="JPEG")
|
||||
else:
|
||||
image = Image.open(file)
|
||||
image.thumbnail((2000, 2000))
|
||||
image.save(path)
|
||||
|
||||
|
||||
def redirect_with_flash(
|
||||
|
Reference in New Issue
Block a user