[英]crop and save uploaded image with python and PIL
i am having a problem crop the uploaded image and save it.我在裁剪上传的图像并保存时遇到问题。 I am using Cherrypy.
我正在使用 Cherrypy。
@cherrypy.expose
def uploadphoto(self, **data):
photo = data['photo']
original_image = Image.open(StringIO(photo.file)) //error happen here
box = (0, 0, 100, 100)
cropped_image = photo.crop(original_image)
path = 'uploads/myphoto.jpg'
cropped_image.save(path, 'JPEG');
here is the form:这是表格:
<form id="form" action="uploadphoto" method="post" enctype="multipart/form-data">
<input type='file' name="photo"/>
<input type="submit" value="save" />
</form>
is there anything wrong?有什么不对的吗? i am new to python, please help me out.
我是python的新手,请帮帮我。
尝试通过以下方式将文件指针重置为文件开头:
photo.file.seek(0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.