mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 11:36:16 +00:00
Correct missing Exif data
Format missed information
This commit is contained in:
parent
da1579555b
commit
c02d618844
6 changed files with 266 additions and 179 deletions
|
@ -1,88 +0,0 @@
|
|||
from flask import Blueprint, flash, g, redirect, render_template, request, url_for, jsonify, current_app
|
||||
from werkzeug.exceptions import abort
|
||||
from werkzeug.utils import secure_filename
|
||||
|
||||
from gallery.auth import login_required
|
||||
from gallery.db import get_db
|
||||
|
||||
from . import metadata as mt
|
||||
from PIL import Image
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
dt = datetime.now()
|
||||
|
||||
blueprint = Blueprint('gallery', __name__)
|
||||
|
||||
|
||||
def human_size(num, suffix="B"):
|
||||
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
|
||||
if abs(num) < 1024.0:
|
||||
return f"{num:3.1f}{unit}{suffix}"
|
||||
num /= 1024.0
|
||||
return f"{num:.1f}Yi{suffix}"
|
||||
|
||||
|
||||
@blueprint.route('/')
|
||||
def index():
|
||||
db = get_db()
|
||||
images = db.execute('SELECT * FROM posts'
|
||||
' ORDER BY created_at DESC').fetchall()
|
||||
|
||||
return render_template('index.html', images=images)
|
||||
|
||||
|
||||
@blueprint.route('/image/<int:id>')
|
||||
def image(id):
|
||||
# Get image from database
|
||||
db = get_db()
|
||||
image = db.execute('SELECT * FROM posts WHERE id = ?', (id, )).fetchone()
|
||||
|
||||
if image is None:
|
||||
abort(404)
|
||||
|
||||
exif = mt.metadata.yoink(os.path.join(current_app.config['UPLOAD_FOLDER'], image['file_name']))
|
||||
file_size = human_size(os.path.getsize(os.path.join(current_app.config['UPLOAD_FOLDER'], image['file_name'])))
|
||||
|
||||
try:
|
||||
width = exif['File']['Width']['value']
|
||||
height = exif['File']['Height']['value']
|
||||
except:
|
||||
try:
|
||||
width, height = Image.open(os.path.join(current_app.config['UPLOAD_FOLDER'], image['file_name'])).size
|
||||
except:
|
||||
width, height = 0, 0
|
||||
|
||||
return render_template('image.html', image=image, exif=exif, file_size=file_size, width=width, height=height)
|
||||
|
||||
|
||||
@blueprint.route('/group')
|
||||
def groups():
|
||||
return render_template('group.html', group_id='gwa gwa')
|
||||
|
||||
|
||||
@blueprint.route('/group/<int:id>')
|
||||
def group(id):
|
||||
return render_template('group.html', group_id=id)
|
||||
|
||||
|
||||
@blueprint.route('/upload')
|
||||
@login_required
|
||||
def upload():
|
||||
return render_template('upload.html')
|
||||
|
||||
|
||||
@blueprint.route('/profile')
|
||||
def profile():
|
||||
return render_template('profile.html', user_id='gwa gwa')
|
||||
|
||||
|
||||
@blueprint.route('/profile/<int:id>')
|
||||
def profile_id(id):
|
||||
return render_template('profile.html', user_id=id)
|
||||
|
||||
|
||||
@blueprint.route('/settings')
|
||||
@login_required
|
||||
def settings():
|
||||
return render_template('settings.html')
|
Loading…
Add table
Add a link
Reference in a new issue