PIL: ValueError: unknown resampling filter, How to resize images uploaded on Flask?

佐手、 提交于 2020-06-24 21:30:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!