From 2d88a65ead8df25508d52605a323be110372eb4d Mon Sep 17 00:00:00 2001 From: Cam Date: Sun, 10 Jan 2021 18:07:56 +1100 Subject: [PATCH] WARNING: CURRENTLY BROKEN... updated photos.py to use exif data for thumbnails, and templates/photos.html to reflect changes --- photos.py | 29 +++++++++++++++++++++++++++-- templates/photos.html | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/photos.py b/photos.py index 4540181..91bfb58 100644 --- a/photos.py +++ b/photos.py @@ -10,6 +10,8 @@ import glob from PIL import Image from pymediainfo import MediaInfo import hashlib +import exifread +import base64 ################################################################################ # Local Class imports @@ -39,7 +41,7 @@ class Photos(db.Model): size_MB = db.Column(db.Integer, unique=False, nullable=False) # hash might not be unique, this could be the source of dupe problems hash = db.Column(db.Integer, unique=True, nullable=True) - thumnbnail = db.Column(db.BYTE, unique=False, nullable=False) + thumbnail = db.Column(db.LargeBinary, unique=False, nullable=True) def __repr__(self): return "".format(self.id, self.name ) @@ -61,10 +63,14 @@ def photos(): view_path = p file_list.append(glob.glob(view_path + '**', recursive=True)) for file in file_list[0]: + fthumbnail = None + if file == p: + continue if os.path.isdir(file): ftype = 'Directory' elif isImage(file): ftype = 'Image' + fthumbnail = getExif(file) elif isVideo(file): ftype = 'Video' else: @@ -75,8 +81,13 @@ def photos(): fhash=md5(file) else: fhash=None + + + fsize = round(os.stat(file).st_size/(1024*1024)) - view_list.append( Photos( name=file, type=ftype, size_MB=fsize, hash=fhash )) + view_list.append( Photos( name=file, type=ftype, size_MB=fsize, hash=fhash, thumbnail=fthumbnail )) + + return render_template("photos.html", page_title='View Photos', view_path=view_path, file_list=view_list, alert=st.GetAlert(), message=st.GetMessage() ) @@ -97,3 +108,17 @@ def isVideo(file): return False except Exception as e: return False + +def getExif(file): + f = open(file, 'rb') + try: + tags = exifread.process_file(f) + except: + print('NO EXIF TAGS?!?!?!?') + f.close() + raise + f.close() + + fthumbnail = base64.b64encode(tags['JPEGThumbnail']) + + return fthumbnail \ No newline at end of file diff --git a/templates/photos.html b/templates/photos.html index 5ca9703..822cef9 100644 --- a/templates/photos.html +++ b/templates/photos.html @@ -17,7 +17,7 @@ {% endif %}  {{obj.name}} {% if obj.type=="Image" %} - + {% endif %} {{obj.size_MB}}{{obj.hash}} {% endfor %}