Browse Source

resize images upon upload using pillow

master
crunk 1 year ago
parent
commit
f288d22994
  1. 2
      library/csvparser/varlib.csv
  2. 13
      library/page.py
  3. BIN
      library/static/images/image-64.jpg
  4. 1
      requirements.txt

2
library/csvparser/varlib.csv

@ -53,4 +53,4 @@ Id,Publication,Author,Year,Custodian,Fields,Type,Publishers,License,LicenseShort
61,Mots de la cage aux ours - woorden uit de berenkuil,Constant,2012,Varia,"words, language, Bruxelles",Softcover,Constant,Copyleft,Copyleft,,,
62,Snake rituals and switching circuits,Florian Cramer,2009,Danny,"mass communication, personal communication, new media",paperback,Piet Zwart Institute,Creative Commons Attribution-Share Alike 3.0,Creative Commons,The function of a medium is ultimately decided by its users and not by its creators,,
63,Magium issue 1: On Eating in isolation,Alice Strete,2020,Varia,"food, sharing, personal stories, consumption",zine,Self Published,Free Art License,Free Art License,,,No one
64,Networks of One's Own: three takes on taking care,"Varia, Constant and Colm O’Neill",2019,Varia,"Software, internet, taking care, homebrew",paperback,Varia,Copyleft,Copyleft,,Networks Of One’s Own is a periodic para-nodal1 publication that is itself collectively within a network2.,
64,Networks of One's Own 2: three takes on taking care,"Varia, Constant and Colm O’Neill",2019,Danny,"Software, internet, taking care, homebrew",paperback,Varia,Copyleft,Copyleft,Networks Of One’s Own is a periodic para-nodal publication that is itself collectively within a network.,,Danny

Can't render this file because it has a wrong number of fields in line 10.

13
library/page.py

@ -14,6 +14,7 @@ from flask import (
)
from flask_wtf.csrf import CSRFProtect
from werkzeug.utils import secure_filename
from PIL import Image
from rnrfeed.rnrfeeder import getevents, getlatestevent
from uploadform import PublicationForm
from borrowform import BorrowForm
@ -31,6 +32,7 @@ from csvparser.csvparser import (
csrf = CSRFProtect()
APP = flask.Flask(__name__, static_folder="static")
APP.config['SECRET_KEY'] = 'ty4425hk54a21eee5719b9s9df7sdfklx'
APP.config['UPLOAD_FOLDER'] = 'tmpupload'
csrf.init_app(APP)
@ -128,9 +130,16 @@ def upcoming_or_latest():
def saveimage(image, id):
"""helper function that can save images"""
print(image.filename)
image.save(os.path.join(APP.config['UPLOAD_FOLDER'], image.filename))
orig_image = Image.open(
os.path.join(APP.config['UPLOAD_FOLDER'] ,image.filename)
)
new_width = 640
new_height = int(new_width * orig_image.height / orig_image.width)
resized_image = orig_image.resize((new_width, new_height), Image.ANTIALIAS)
filename = secure_filename("image-{0}.jpg".format(id))
image.save(os.path.join("static/images/", filename))
resized_image.save(os.path.join("static/images/", filename))
os.remove(os.path.join(APP.config['UPLOAD_FOLDER'], image.filename))
def checksecret(secret):

BIN
library/static/images/image-64.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 31 KiB

1
requirements.txt

@ -3,4 +3,5 @@ feedparser
flask
flask_wtf
requests
Pillow
bcrypt

Loading…
Cancel
Save