How to resize pictures uploaded by Flask

File upload uses flask-uploads plug-in, added a function to change the file name change_filename, now hopes to add a zoom function, custom width and height, only save the scaled image, the current code is as follows:

@admin.route("/post/new", methods=["GET", "POST"])
@login_required
def post_new():
    form = PostForm()
    if form.validate_on_submit():
        title = form.title.data
        photo_filename = change_filename(form.photo.data.filename)
        photo = photos.save(form.photo.data, name=photo_filename)
        post = Post(title=title, photo=photo)
        db.session.add(post)
        db.session.commit()
        return redirect(url_for("admin.post_manage"))
    return render_template("admin/post_new.html", form=form)

ask prawns how to write! Thank you!


< H2 > dependence < / H2 >

PLI
python3.x

< H2 > Code < / H2 >
from PIL import Image


old_file = "1.jpg"
new_file = "1_t.jpg"

sImg = Image.open(old_file)
w, h = sImg.size
print(w,h)

dImg = sImg.resize((int(w / 2), int(h / 2)), Image.ANTIALIAS)
dImg.save(new_file)

print("")

sImg_t = Image.open(new_file)
w, h = sImg_t.size
print(w,h)
< H2 > results < / H2 >
600 400

300 200

t1
t2

you can leave this new picture and save

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf49db-535aa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf49db-535aa.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?