问题
I'm making a web app using Flask, and I want to resize the images that are uploaded. I'm using PIL to do this, but an error is thrown.
The process to do it is like this, but it seems inefficient:
filename = secure_filename(form.image.data.filename)
form.image.data.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
img = Image.open(os.path.join(app.config['UPLOAD_FOLDER'],filename), 'r')
img = img.resize(300, 300)
img.save(filename, quality=100, optimize=True)
What I'm trying to do is save the image after the user uploaded it, open the new file, resize it, and save it again.
How can I fix my error?
Also is there a way to do this more efficiently (without saving the un-resized file), using a Python library?
回答1:
img = img.resize(300, 300)
=> img = img.resize((300,300))
来源:https://stackoverflow.com/questions/49565298/pil-valueerror-unknown-resampling-filter-how-to-resize-images-uploaded-on-fla