0

我正在学习 django,但我很难理解图像文件处理的工作原理。

def upload_file(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            handle_uploaded_file(request.FILES['file'])
            return HttpResponseRedirect('/success/url/')
    else:
        form = UploadFileForm()
    return render_to_response('upload.html', {'form': form})

这是来自https://docs.djangoproject.com/en/dev/topics/http/file-uploads/的一个例子, 如果我想处理图像的大小和存储,handle_uploaded_file() 函数应该如何?谢谢

4

1 回答 1

0

像这样的东西:

import Image
def handle_uploaded_file(file):
 myimg = Image.open(file)
 myimg = myimg.resize((1024,1024),Image.ANTIALIAS)
 myimg.save('/home/arpit/myimg.png')
 #... rest of the code
于 2013-09-12T09:45:20.593 回答