python libheif
This commit is contained in:
22
app.py
22
app.py
@@ -6,7 +6,7 @@ import mimetypes
|
||||
import sys
|
||||
import platform
|
||||
import psutil
|
||||
import pyheif # zdjecia heic
|
||||
from pillow_heif import register_heif_opener
|
||||
|
||||
from datetime import datetime, timedelta, UTC, timezone
|
||||
|
||||
@@ -48,6 +48,7 @@ from functools import wraps
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
register_heif_opener() # pillow_heif dla HEIC
|
||||
|
||||
ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "gif", "webp", "heic"}
|
||||
SQLALCHEMY_ECHO = True
|
||||
@@ -242,19 +243,16 @@ def enrich_list_data(l):
|
||||
l.total_expense = sum(e.amount for e in expenses)
|
||||
return l
|
||||
|
||||
|
||||
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)
|
||||
image = Image.open(file)
|
||||
image.thumbnail((2000, 2000))
|
||||
|
||||
if image.format == "HEIF":
|
||||
path = path.rsplit(".", 1)[0] + ".jpg"
|
||||
image = image.convert("RGB")
|
||||
image.save(path, format="JPEG")
|
||||
else:
|
||||
image.save(path)
|
||||
|
||||
def redirect_with_flash(
|
||||
message: str, category: str = "info", endpoint: str = "main_page"
|
||||
|
Reference in New Issue
Block a user