Skip to content

Commit

Permalink
Fine tuning image display
Browse files Browse the repository at this point in the history
  • Loading branch information
villanueval committed Aug 22, 2024
1 parent 7c2e0ca commit 45680cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions web_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# from PIL import ImageFont
# from PIL import ImageDraw
from uuid import UUID

from pathlib import Path
from time import strftime
from time import localtime

Expand Down Expand Up @@ -3265,7 +3265,7 @@ def get_preview(file_id=None, max=None, sensitive=None):
except:
raise InvalidUsage('invalid file_id value', status_code=400)

data = run_query("SELECT folder_id FROM files WHERE file_id = %(file_id)s LIMIT 1", {'file_id': file_id})
data = run_query("SELECT folder_id, file_name FROM files WHERE file_id = %(file_id)s LIMIT 1", {'file_id': file_id})
logger.info(data)
max = request.args.get('max')
dl = request.args.get('dl')
Expand Down Expand Up @@ -3294,8 +3294,8 @@ def get_preview(file_id=None, max=None, sensitive=None):
else:
logger.info(filename)
# img = Image.open(filename)
# wpercent = (int(width) / float(img.size[0]))
# hsize = int((float(img.size[1]) * float(wpercent)))
wpercent = (int(width) / float(img.size[0]))
hsize = int((float(img.size[1]) * float(wpercent)))
img = img.resize((int(width), hsize), Image.LANCZOS)
filename = "/tmp/{}_{}.jpg".format(file_id, width)
img.save(filename, icc_profile=img.info.get('icc_profile'))
Expand Down Expand Up @@ -3348,7 +3348,8 @@ def get_preview(file_id=None, max=None, sensitive=None):
else:
filename = "static/na.jpg"
if dl == "1":
return send_file(filename, mimetype='image/jpeg', as_attachment=True)
dl_filename = file_stem = Path(data[0]['file_name']).stem
return send_file(filename, mimetype='image/jpeg', attachment_filename=dl_filename, as_attachment=True)
else:
try:
return send_file(filename, mimetype='image/jpeg')
Expand Down
4 changes: 2 additions & 2 deletions web_app/templates/file.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ <h2>Image Preview:</h2>

{% if file_details.preview_image_ext == None %}

<img src="{{ url_for('get_preview', file_id=file_details.file_id, max=600) }}" alt="Preview image of {{ file_details.file_name }}" class="img-fluid card-img-top">
<p><a href="{{ url_for('get_fullsize', file_id=file_details.file_id) }}" rel="noopener noreferrer" title="Open JPG in full size of {{ file_details.file_name }}"><img src="{{ url_for('get_preview', file_id=file_details.file_id, max=600) }}" alt="Preview image of {{ file_details.file_name }}" class="img-fluid card-img-top"><br>

<p><a href="{{ url_for('get_fullsize', file_id=file_details.file_id) }}" rel="noopener noreferrer" title="Open JPG in full size of {{ file_details.file_name }}">Open JPG in full size</a><br>
Open JPG in full size</a><br>
<a href="{{ url_for('get_preview', file_id=file_details.file_id, dl=1) }}" rel="noopener noreferrer" title="Download JPG in full size of {{ file_details.file_name }}"><i class="fa-solid fa-download"></i> Download JPG in full size</a></p>

{% else %}
Expand Down

0 comments on commit 45680cf

Please sign in to comment.