mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-03 00:31:25 -08:00
properly resize image posts
This commit is contained in:
parent
e15d2a0581
commit
fb046f1acb
1 changed files with 5 additions and 2 deletions
|
@ -255,6 +255,7 @@ def save_post(form, post: Post):
|
|||
|
||||
# save the file
|
||||
final_place = os.path.join(directory, new_filename + file_ext)
|
||||
final_place_medium = os.path.join(directory, new_filename + '_medium.webp')
|
||||
final_place_thumbnail = os.path.join(directory, new_filename + '_thumbnail.webp')
|
||||
uploaded_file.seek(0)
|
||||
uploaded_file.save(final_place)
|
||||
|
@ -270,9 +271,11 @@ def save_post(form, post: Post):
|
|||
img = ImageOps.exif_transpose(img)
|
||||
img_width = img.width
|
||||
img_height = img.height
|
||||
img.thumbnail((2000, 2000))
|
||||
img.save(final_place)
|
||||
if img.width > 512 or img.height > 512:
|
||||
img.thumbnail((512, 512))
|
||||
img.save(final_place)
|
||||
img.save(final_place_medium, format="WebP", quality=93)
|
||||
img_width = img.width
|
||||
img_height = img.height
|
||||
# save a second, smaller, version as a thumbnail
|
||||
|
@ -281,7 +284,7 @@ def save_post(form, post: Post):
|
|||
thumbnail_width = img.width
|
||||
thumbnail_height = img.height
|
||||
|
||||
file = File(file_path=final_place, file_name=new_filename + file_ext, alt_text=alt_text,
|
||||
file = File(file_path=final_place_medium, file_name=new_filename + file_ext, alt_text=alt_text,
|
||||
width=img_width, height=img_height, thumbnail_width=thumbnail_width,
|
||||
thumbnail_height=thumbnail_height, thumbnail_path=final_place_thumbnail,
|
||||
source_url=final_place.replace('app/static/', f"https://{current_app.config['SERVER_NAME']}/static/"))
|
||||
|
|
Loading…
Add table
Reference in a new issue