if form is_valid if request FILES today_time int time time file1 Strin

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
if form.is_valid():
if request.FILES:
today_time = int(time.time())
file1 = StringIO.StringIO(form.cleaned_data['photo'].content)
photo = Image.open(file1)
x,y = photo.size
min_size = min(x, y)
region = photo.crop((0, 0, min_size, min_size))
region.thumbnail((100, 100))
region.save('%s/images/%s.jpg' % ('/home/offline/django/muzx/static', today_time),'JPEG')
photo.save('%s/original/images/%s.jpg' % ('/home/offline/django/muzx/static', today_time),'JPEG')
Photo.objects.create(user=request.user,photo='images/%s.jpg' % today_time)
return HttpResponseRedirect('/profile/')