equal
deleted
inserted
replaced
81 profile.save() |
81 profile.save() |
82 |
82 |
83 return user |
83 return user |
84 |
84 |
85 def handle_uploaded_photo(user, ufile): |
85 def handle_uploaded_photo(user, ufile): |
|
86 """Handles the upload and gives the file path to be saved. |
|
87 """ |
|
88 |
86 usermedia = settings.USER_MEDIA_ROOT |
89 usermedia = settings.USER_MEDIA_ROOT |
87 filename = ufile.name |
90 filename = ufile.name |
88 ext = filename.split('.')[-1] |
91 ext = filename.split('.')[-1] |
89 filesize = ufile.size |
92 |
90 filecontent = ufile.read() |
93 filecontent = ufile.read() |
91 userfilename = 'user-%d.%s' % (user.id, ext) |
94 userfilename = 'user-%d.%s' % (user.id, ext) |
92 if not filecontent: |
95 if not filecontent: |
93 return None |
96 return None |
94 |
97 |
117 elif pr < nr: |
120 elif pr < nr: |
118 # photo aspect is taller than destination ratio |
121 # photo aspect is taller than destination ratio |
119 th = int(round(nw / pr)) |
122 th = int(round(nw / pr)) |
120 image = image.resize((nw, th), Image.ANTIALIAS) |
123 image = image.resize((nw, th), Image.ANTIALIAS) |
121 t = int(round(( th - nh ) / 2.0)) |
124 t = int(round(( th - nh ) / 2.0)) |
122 #print((0, t, nw, t + nh)) |
|
123 image = image.crop((0, t, nw, t + nh)) |
125 image = image.crop((0, t, nw, t + nh)) |
124 else: |
126 else: |
125 # photo aspect matches the destination ratio |
127 # photo aspect matches the destination ratio |
126 image = image.resize((nw, nh), Image.ANTIALIAS) |
128 image = image.resize((nw, nh), Image.ANTIALIAS) |
127 |
129 |
128 image.save(str(foutname)) |
130 image.save(str(foutname)) |
129 return userfilename |
131 return userfilename |
130 |
|