adding exif data start

This commit is contained in:
crunk 2024-06-23 14:19:38 +02:00
parent b7310c837b
commit e5d8da2568
2 changed files with 28 additions and 0 deletions

View File

@ -14,6 +14,7 @@ from sqlalchemy.exc import (
InterfaceError,
InvalidRequestError,
)
from exif import Image
from app import db
from models.distribusi_model import Distribusis
from models.distribusi_file_model import DistribusiFiles
@ -51,6 +52,7 @@ def describe_file(file_id):
distribusi_file.id, distribusi_file.path, distribusi_file.type
)
save_described_file_to_db(describe_form, distribusi_file)
add_exif_to_image(describe_form, distribusi_file)
distribusi = Distribusis.query.filter_by(
id=distribusi_file.distribusi
).first()
@ -110,3 +112,21 @@ def save_described_file_to_db(describe_form, distribusi_file):
db.session.rollback()
describe_form.save.errors.append("Error connecting to the database")
flash("Error connecting to the database", "danger")
def add_exif_to_image(describe_form, distribusi_file):
if not describe_form.alttext.data:
return
if distribusi_file.type != "image":
return
updating_image = bytearray()
with open(distribusi_file.path, "rb") as image_file:
image_bytes = image_file.read()
updating_image = Image(image_bytes)
updating_image.communication = describe_form.alttext.data
with open(distribusi_file.path, "wb") as new_image_file:
new_image_file.write(updating_image.get_file())
print(
f"{updating_image.communication} is set from form data: {describe_form.alttext.data}"
)
return

View File

@ -0,0 +1,8 @@
from flask_wtf import FlaskForm
from wtforms import SubmitField
class DistribusiForm(FlaskForm):
"""Distribusi class to launch your distribusi website"""
submit = SubmitField("Re-Distribusi!")