我必须调整一个图像的大小并使用django将其上载到服务器,目前我正在使用文件系统存储来上载文件,但是我的代码是
def create_new_event(request, steps=None):
if request.method == 'POST':
stepFirstForm = CreateEventStepFirstForm(request.POST, request.FILES)
if stepFirstForm.is_valid():
if request.FILES['artist_image']:
randomArtistImage = ''.join(random.choice('0123456789ABCDEFabcdefghijklmn') for i in range(8));
myfile = request.FILES['artist_image']
fs = FileSystemStorage()
fileName, fileExtension = os.path.splitext(myfile.name)
artistImageName = randomArtistImage+'-'+str(request.user.id)+str(fileExtension)
filename = fs.save('event_artists_images/'+artistImageName, myfile)
uploaded_artist_image_url = fs.url(filename)
使用这段代码,我可以将图像移动到event_artists_images文件夹,但我还想将此图像调整为300*300像素。我怎么能做到这一点。如果我可以使用PIL图像类,那么在服务器上如何上传和调整文件大小。在
这个问题已经回答了好几次了,除非我遗漏了什么。 这里的答案应该有帮助,例如:Django resize image during upload 或者在这里https://blog.louwii.fr/2016/03/django-resize-an-image-on-upload/
相关问题 更多 >
编程相关推荐